From e5ebe0cb92a72538e195724e351dad905e7ee1db Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Mon, 16 Jun 2014 20:15:23 +0200 Subject: [PATCH] util: fixed memleak in wmsetbg's updateDomain (Coverity #50167) As pointed by Coverity, the function wstrconcat is allocating memory to return its result, which is not freed in old coding of the function. This patch uses a local storage buffer to have a simpler code to generate the command to bu run with 'system' without leak. Signed-off-by: Christophe CURIS --- util/wmsetbg.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/util/wmsetbg.c b/util/wmsetbg.c index 80a845e2..41e1d116 100644 --- a/util/wmsetbg.c +++ b/util/wmsetbg.c @@ -992,13 +992,14 @@ static void updateDomain(const char *domain, const char *key, const char *textur { int result; char *program = "wdwrite"; + char cmd_smooth[1024]; - /* here is a mem leak */ - result = system(wstrconcat("wdwrite ", - wstrconcat(domain, smooth ? " SmoothWorkspaceBack YES" : " SmoothWorkspaceBack NO"))); - + snprintf(cmd_smooth, sizeof(cmd_smooth), + "wdwrite %s SmoothWorkspaceBack %s", + domain, smooth ? "YES" : "NO"); + result = system(cmd_smooth); if (result == -1) - werror("error executing system command"); + werror("error executing system(\"%s\")", cmd_smooth); execlp(program, program, domain, key, texture, NULL); wwarning("warning could not run \"%s\"", program); -- 2.11.4.GIT