diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index 029a542..f545021 100644 --- a/src/cairo-xlib-surface.c +++ b/src/cairo-xlib-surface.c @@ -840,13 +840,15 @@ _get_image_surface (cairo_xlib_surface_t *surface, * retry, but to keep things simple, we just create a * temporary pixmap */ + cairo_xlib_error_func_t old_handler; Pixmap pixmap; GC gc; status = _cairo_xlib_surface_get_gc (display, surface, &gc); if (unlikely (status)) - goto BAIL; + goto BAIL2; + old_handler = XSetErrorHandler (_noop_error_handler); pixmap = XCreatePixmap (display->display, surface->drawable, extents->width, extents->height, @@ -873,12 +875,13 @@ _get_image_surface (cairo_xlib_surface_t *surface, XFreePixmap (display->display, pixmap); } + XSetErrorHandler (old_handler); _cairo_xlib_surface_put_gc (display, surface, gc); if (ximage == NULL) { status = _cairo_error (CAIRO_STATUS_NO_MEMORY); - goto BAIL; + goto BAIL2; } } @@ -1005,15 +1008,17 @@ _get_image_surface (cairo_xlib_surface_t *surface, } BAIL: + if (unlikely (status)) + cairo_surface_destroy (&image->base); + + BAIL2: if (ximage) XDestroyImage (ximage); cairo_device_release (&display->base); - if (unlikely (status)) { - cairo_surface_destroy (&image->base); + if (unlikely (status)) return _cairo_surface_create_in_error (status); - } return &image->base; }