From 6c3cd08dade58b4757b36938c02d650b068c5828 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 14 Jun 2014 19:34:05 +0200 Subject: [PATCH] wrlib: return NULL if XImage could not be taken, for consistency To be consistent with RCreateXImage and because it should not be up to the caller to handle this, when XGetImage returns a NULL pointer then the function RGetXImage will also return NULL instead of an RXImage structure with a NULL pointer. This consistent behaviour helps fixing a memory leak in WMaker reported by Coverity (#50125). Signed-off-by: Christophe CURIS --- src/workspace.c | 4 +--- wrlib/xutil.c | 8 ++++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/workspace.c b/src/workspace.c index d58f9046..0fc6e626 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -390,10 +390,8 @@ static void showWorkspaceName(WScreen * scr, int workspace) } ximg = RGetXImage(scr->rcontext, scr->root_win, px, py, data->text->width, data->text->height); - - if (!ximg || !ximg->image) { + if (!ximg) goto erro; - } XMapRaised(dpy, scr->workspace_name); XFlush(dpy); diff --git a/wrlib/xutil.c b/wrlib/xutil.c index 82122d4b..3baa861d 100644 --- a/wrlib/xutil.c +++ b/wrlib/xutil.c @@ -207,7 +207,6 @@ RXImage *RGetXImage(RContext * context, Drawable d, int x, int y, unsigned width ximg->is_shared = 0; ximg->image = XGetImage(context->dpy, d, x, y, width, height, AllPlanes, ZPixmap); } - return ximg; #else /* !USE_XSHM */ ximg = malloc(sizeof(RXImage)); if (!ximg) { @@ -216,9 +215,14 @@ RXImage *RGetXImage(RContext * context, Drawable d, int x, int y, unsigned width } ximg->image = XGetImage(context->dpy, d, x, y, width, height, AllPlanes, ZPixmap); +#endif /* !USE_XSHM */ + + if (ximg->image == NULL) { + free(ximg); + return NULL; + } return ximg; -#endif /* !USE_XSHM */ } void