From: Donghwa Jeong Date: Mon, 11 Jun 2018 05:51:16 +0000 (+0900) Subject: coverity: #1425781 X-Git-Tag: lxc-3.1.0~258^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7177e6b155546b06865b770be81992a90095d7d1;p=thirdparty%2Flxc.git coverity: #1425781 Resource leak Signed-off-by: Donghwa Jeong --- diff --git a/src/lxc/criu.c b/src/lxc/criu.c index de2bc6773..1ff4caef8 100644 --- a/src/lxc/criu.c +++ b/src/lxc/criu.c @@ -868,14 +868,14 @@ static bool criu_ok(struct lxc_container *c, char **criu_version) { struct lxc_list *it; - if (!criu_version_ok(criu_version)) - return false; - if (geteuid()) { ERROR("Must be root to checkpoint"); return false; } + if (!criu_version_ok(criu_version)) + return false; + /* We only know how to restore containers with veth networks. */ lxc_list_for_each(it, &c->lxc_conf->network) { struct lxc_netdev *n = it->elem; @@ -887,6 +887,10 @@ static bool criu_ok(struct lxc_container *c, char **criu_version) break; default: ERROR("Found un-dumpable network: %s (%s)", lxc_net_type_to_str(n->type), n->name); + if (criu_version) { + free(*criu_version); + *criu_version = NULL; + } return false; } } @@ -1239,6 +1243,7 @@ static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *op ret = pipe(criuout); if (ret < 0) { SYSERROR("pipe() failed"); + free(criu_version); return false; } @@ -1299,6 +1304,7 @@ static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *op if (w == -1) { SYSERROR("waitpid"); close(criuout[0]); + free(criu_version); return false; } @@ -1327,6 +1333,8 @@ static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *op if (!ret) ERROR("criu output: %s", buf); + + free(criu_version); return ret; } fail: @@ -1366,9 +1374,6 @@ bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts) int pipefd[2]; char *criu_version = NULL; - if (!criu_ok(c, &criu_version)) - return false; - if (geteuid()) { ERROR("Must be root to restore"); return false; @@ -1379,10 +1384,17 @@ bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts) return false; } + if (!criu_ok(c, &criu_version)) { + close(pipefd[0]); + close(pipefd[1]); + return false; + } + pid = fork(); if (pid < 0) { close(pipefd[0]); close(pipefd[1]); + free(criu_version); return false; } @@ -1393,6 +1405,7 @@ bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts) } close(pipefd[1]); + free(criu_version); nread = read(pipefd[0], &status, sizeof(status)); close(pipefd[0]);