From: Christophe CURIS <christophe.cu...@free.fr> 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 <christophe.cu...@free.fr> --- 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 d58f904..0fc6e62 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 82122d4..3baa861 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 -- 1.9.2 -- To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.