As pointed by Coverity, there was a memory leak because the buffer used to
create the wmsetbg command is allocated twice.

Because it is not really necessary to call 'wmalloc' for such a small case
(it is not efficient and participates to memory fragmentation), this patch
replaces the dynamic memory allocation by a buffer on the stack, which also
solves to de-allocation issue.

Signed-off-by: Christophe CURIS <[email protected]>
---
 src/defaults.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/defaults.c b/src/defaults.c
index ee027dc..b6e855c 100644
--- a/src/defaults.c
+++ b/src/defaults.c
@@ -3088,23 +3088,21 @@ static int setWorkspaceBack(WScreen * scr, 
WDefaultEntry * entry, void *tdata, v
                        }
                }
        } else if (WMGetPropListItemCount(value) > 0) {
-               char *command;
                char *text;
                char *dither;
                int len;
 
                text = WMGetPropListDescription(value, False);
                len = strlen(text) + 40;
-               command = wmalloc(len);
                dither = wPreferences.no_dithering ? "-m" : "-d";
                if (!strchr(text, '\'') && !strchr(text, '\\')) {
-                       command = wmalloc(len);
+                       char command[len];
+
                        if (wPreferences.smooth_workspace_back)
                                snprintf(command, len, "wmsetbg %s -S -p '%s' 
&", dither, text);
                        else
                                snprintf(command, len, "wmsetbg %s -p '%s' &", 
dither, text);
                        ExecuteShellCommand(scr, command);
-                       wfree(command);
                } else
                        wwarning(_("Invalid arguments for background \"%s\""), 
text);
                wfree(text);
-- 
2.1.4


-- 
To unsubscribe, send mail to [email protected].

Reply via email to