Skip to content

Commit

Permalink
xlib: Fix display closing to work properly
Browse files Browse the repository at this point in the history
Previously we free()'d the cairo_device's memory which was not good at
all. Now the code causes cairo_device_finish() instead.
  • Loading branch information
Benjamin Otte committed Apr 23, 2010
1 parent 637564c commit 1687c7b
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/cairo-xlib-display.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ _cairo_xlib_display_discard_screens (cairo_xlib_display_t *display)
}
}

static void
_cairo_xlib_display_finish (void *abstract_display)
{
cairo_xlib_display_t *display = abstract_display;

display->display = NULL;
}

static void
_cairo_xlib_display_destroy (void *abstract_display)
{
Expand Down Expand Up @@ -201,22 +209,23 @@ _cairo_xlib_close_display (Display *dpy, XExtCodes *codes)
if (display == NULL)
return 0;

/* protect the notifies from triggering XErrors */
XSync (dpy, False);
old_handler = XSetErrorHandler (_noop_error_handler);
if (! cairo_device_acquire (&display->base)) {
/* protect the notifies from triggering XErrors */
XSync (dpy, False);
old_handler = XSetErrorHandler (_noop_error_handler);

if (cairo_device_acquire (&display->base)) {
_cairo_xlib_display_notify (display);
_cairo_xlib_call_close_display_hooks (display);
_cairo_xlib_display_discard_screens (display);
_cairo_xlib_display_notify (display);
_cairo_xlib_call_close_display_hooks (display);
_cairo_xlib_display_discard_screens (display);

/* catch any that arrived before marking the display as closed */
_cairo_xlib_display_notify (display);
cairo_device_release (&display->base);
}
/* catch any that arrived before marking the display as closed */
_cairo_xlib_display_notify (display);

XSync (dpy, False);
XSetErrorHandler (old_handler);
XSync (dpy, False);
XSetErrorHandler (old_handler);

cairo_device_release (&display->base);
}

/*
* Unhook from the global list
Expand Down Expand Up @@ -250,7 +259,7 @@ static const cairo_device_backend_t _cairo_xlib_device_backend = {
NULL,

NULL, /* flush */
NULL, /* finish */
_cairo_xlib_display_finish,
_cairo_xlib_display_destroy,
};

Expand Down

0 comments on commit 1687c7b

Please sign in to comment.