Skip to content

Commit

Permalink
coverity: #1425781
Browse files Browse the repository at this point in the history
Resource leak

Signed-off-by: Donghwa Jeong <dh48.jeong@samsung.com>
  • Loading branch information
2xsec committed Jun 11, 2018
1 parent 8f55c74 commit 7177e6b
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/lxc/criu.c
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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]);
Expand Down

0 comments on commit 7177e6b

Please sign in to comment.