From 04404bf47c4eed536dde614333eb83b923b3ae59 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 25 Apr 2015 12:44:24 +0200 Subject: [PATCH] wmaker: fix memory leak in the Workspace Map if there is no workspace (Coverity #109608) As pointed by Coverity, there is a safety check on the number of workspace which aborts the function, but the storage memory have already been allocated so it would leak this buffer. The case where the number of workspace is 0 is probably not supposed to happen (there should always be at least 1 workspace, the current one), but it is better to keep safety checks, so this patch is moving the check at the beginning so no leak will occur. Signed-off-by: Christophe CURIS --- src/wsmap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/wsmap.c b/src/wsmap.c index e2b67478..3e84c980 100644 --- a/src/wsmap.c +++ b/src/wsmap.c @@ -372,16 +372,18 @@ static void create_mini_workspace(WScreen *scr, WWorkspaceMap *wsmap, W_Workspac static WWorkspaceMap *create_workspace_map(WScreen *scr, W_WorkspaceMap *wsmap_array, int edge) { - WWorkspaceMap *wsmap = wmalloc(sizeof(WWorkspaceMap)); + WWorkspaceMap *wsmap; + + if (scr->workspace_count == 0) + return NULL; + + wsmap = wmalloc(sizeof(*wsmap)); wsmap->border_width = 5; wsmap->edge = edge; wsmap->mini_workspace_width = scr->scr_width / WORKSPACE_MAP_RATIO; wsmap->mini_workspace_height = scr->scr_height / WORKSPACE_MAP_RATIO; - if (scr->workspace_count == 0) - return NULL; - wsmap->scr = scr; wsmap->win = WMCreateWindow(scr->wmscreen, "wsmap"); wsmap->wswidth = WidthOfScreen(DefaultScreenOfDisplay(dpy)); -- 2.11.4.GIT