From: Dwight Engen Date: Fri, 3 May 2013 16:04:01 +0000 (-0400) Subject: coverity: fix leak in error case X-Git-Tag: lxc-1.0.0.alpha1~1^2~235 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8950ee8ebfc9a7f34003f6892b5a7da6aef9fff9;p=thirdparty%2Flxc.git coverity: fix leak in error case Since lxc_execute() is available through the library and is exposed via the API we cannot be sure the caller will immediately exit, so we should take care to free the allocated memory. Signed-off-by: Dwight Engen Signed-off-by: Serge Hallyn --- diff --git a/src/lxc/execute.c b/src/lxc/execute.c index d93e8e17c..9bf33cae6 100644 --- a/src/lxc/execute.c +++ b/src/lxc/execute.c @@ -55,7 +55,7 @@ static char *choose_init(void) ret = snprintf(retv, PATH_MAX, LXCINITDIR "/lxc/lxc-init"); if (ret < 0 || ret >= PATH_MAX) { ERROR("pathname too long"); - return NULL; + goto out1; } ret = stat(retv, &mystat); @@ -65,7 +65,7 @@ static char *choose_init(void) ret = snprintf(retv, PATH_MAX, "/usr/lib/lxc/lxc-init"); if (ret < 0 || ret >= PATH_MAX) { ERROR("pathname too long"); - return NULL; + goto out1; } ret = stat(retv, &mystat); if (ret == 0) @@ -73,11 +73,13 @@ static char *choose_init(void) ret = snprintf(retv, PATH_MAX, "/sbin/lxc-init"); if (ret < 0 || ret >= PATH_MAX) { ERROR("pathname too long"); - return NULL; + goto out1; } ret = stat(retv, &mystat); if (ret == 0) return retv; +out1: + free(retv); return NULL; }