Commit 8950ee8e by Dwight Engen Committed by Serge Hallyn

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: 's avatarDwight Engen <dwight.engen@oracle.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent a2eea3c1
...@@ -55,7 +55,7 @@ static char *choose_init(void) ...@@ -55,7 +55,7 @@ static char *choose_init(void)
ret = snprintf(retv, PATH_MAX, LXCINITDIR "/lxc/lxc-init"); ret = snprintf(retv, PATH_MAX, LXCINITDIR "/lxc/lxc-init");
if (ret < 0 || ret >= PATH_MAX) { if (ret < 0 || ret >= PATH_MAX) {
ERROR("pathname too long"); ERROR("pathname too long");
return NULL; goto out1;
} }
ret = stat(retv, &mystat); ret = stat(retv, &mystat);
...@@ -65,7 +65,7 @@ static char *choose_init(void) ...@@ -65,7 +65,7 @@ static char *choose_init(void)
ret = snprintf(retv, PATH_MAX, "/usr/lib/lxc/lxc-init"); ret = snprintf(retv, PATH_MAX, "/usr/lib/lxc/lxc-init");
if (ret < 0 || ret >= PATH_MAX) { if (ret < 0 || ret >= PATH_MAX) {
ERROR("pathname too long"); ERROR("pathname too long");
return NULL; goto out1;
} }
ret = stat(retv, &mystat); ret = stat(retv, &mystat);
if (ret == 0) if (ret == 0)
...@@ -73,11 +73,13 @@ static char *choose_init(void) ...@@ -73,11 +73,13 @@ static char *choose_init(void)
ret = snprintf(retv, PATH_MAX, "/sbin/lxc-init"); ret = snprintf(retv, PATH_MAX, "/sbin/lxc-init");
if (ret < 0 || ret >= PATH_MAX) { if (ret < 0 || ret >= PATH_MAX) {
ERROR("pathname too long"); ERROR("pathname too long");
return NULL; goto out1;
} }
ret = stat(retv, &mystat); ret = stat(retv, &mystat);
if (ret == 0) if (ret == 0)
return retv; return retv;
out1:
free(retv);
return NULL; return NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment