Skip to content

Commit

Permalink
Fixed crash on loss of window data stored in deallocated client.
Browse files Browse the repository at this point in the history
  • Loading branch information
alisabedard committed Dec 7, 2016
1 parent f8a3346 commit 273c946
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
20 changes: 18 additions & 2 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,20 @@ static void set_state_not_focused(struct JBWMClient * restrict c)
jbwm_ewmh_remove_state(c->d, c->window, jbwm_ewmh_get_atom(
JBWM_EWMH_WM_STATE_FOCUSED));
}
static bool check_current(void)
{
if (jbwm_client_data.current) {
if (!jbwm_client_data.current->d) {
jbwm_client_data.current = NULL;
return false;
}
return true;
}
return false;
}
static void unselect_current(void)
{
if(jbwm_client_data.current)
if (check_current())
set_state_not_focused(jbwm_client_data.current);
}
static void set_border(struct JBWMClient * restrict c)
Expand All @@ -104,9 +115,14 @@ static void set_focused(struct JBWMClient * c)
static void set_active_window(struct JBWMClient * c)
{
unselect_current(); // depends on jbwm_client_data.current
/* Store the window id as a static variable here in case
* client c is freed. If the property is read after the
* client is freed, it will cause a segmentation fault. */
static jbwm_window_t w;
w = c->window;
jbwm_set_property(c->d, jbwm_get_root(c),
jbwm_ewmh_get_atom(JBWM_EWMH_ACTIVE_WINDOW),
XA_WINDOW, &(c->parent), 1);
XA_WINDOW, &w, 1);
jbwm_client_data.current = c;
}
void jbwm_select_client(struct JBWMClient * c)
Expand Down
13 changes: 7 additions & 6 deletions events.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void jbwm_event_loop(Display * restrict d)
case MappingNotify:
case MotionNotify:
// ignore
break;
continue;
case ConfigureNotify:
JBWM_LOG("ConfigureNotify");
/* Failure to do this causes Java Swing
Expand All @@ -162,15 +162,16 @@ void jbwm_event_loop(Display * restrict d)
/* Sometimes, we were getting a client with a
* NULL display pointer within, check for this
* before going any further. */
if(c && (ev.xcrossing.window == c->parent) &&
c->d)
JBWM_LOG("\t\t\tEnterNotify: xc.detail: %d",
ev.xcrossing.detail);
if (c && c->d && ev.xcrossing.window == c->parent)
jbwm_select_client(c);
break;
continue;
#ifdef JBWM_USE_TITLE_BAR
case Expose:
if (c && !ev.xexpose.count)
jbwm_update_title_bar(c);
break;
continue;
#endif//JBWM_USE_TITLE_BAR
#ifdef JBWM_USE_EWMH
case CreateNotify:
Expand Down Expand Up @@ -210,7 +211,7 @@ void jbwm_event_loop(Display * restrict d)
XInstallColormap(ev.xcolormap.display,
c->cmap);
}
break;
continue;
#ifdef JBWM_USE_EWMH
case ClientMessage:
jbwm_ewmh_handle_client_message(&ev.xclient, c);
Expand Down
6 changes: 3 additions & 3 deletions typedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#define JBWM_TYPEDEF_H
#include <stdint.h>
#include <X11/Xlib.h>
typedef uint32_t jbwm_window_t;
typedef Window jbwm_window_t;
typedef uint32_t jbwm_pixel_t;
typedef uint32_t jbwm_cmap_t;
typedef uint32_t jbwm_atom_t;
typedef Colormap jbwm_cmap_t;
typedef Atom jbwm_atom_t;
typedef uint16_t jbwm_length_t;
typedef int16_t jbwm_axis_t;
#endif//!JBWM_TYPEDEF_H
10 changes: 6 additions & 4 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
#include <stdbool.h>
void jbwm_set_property(Display * restrict d, const jbwm_window_t win,
const jbwm_atom_t property, const jbwm_atom_t type,
void * restrict data, int16_t size)
void * restrict data, uint16_t size)
{
if (d)
XChangeProperty(d, win, property, type,
32, PropModeReplace, data, size);
if (!d)
return;
XChangeProperty(d, win, property, type, 32, PropModeReplace,
data, size);
XFlush(d);
}
jbwm_pixel_t jbwm_get_pixel(Display * restrict dpy,
const uint8_t screen, const char * restrict name)
Expand Down
2 changes: 1 addition & 1 deletion util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "typedef.h"
void jbwm_set_property(Display * restrict d, const jbwm_window_t win,
const jbwm_atom_t property, const jbwm_atom_t type,
void * restrict data, int16_t size);
void * restrict data, uint16_t size);
jbwm_pixel_t jbwm_get_pixel(Display * restrict d, const uint8_t screen,
const char * restrict name);
// Free the result with XFree
Expand Down

0 comments on commit 273c946

Please sign in to comment.