mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
files-reg: Eliminate memory leak in open_remap_ghost on errors
xmalloc'ed gf and gf->path are not freed if something failed. Not a big deal since we're ususally interrupt program execution on error and do exit, but anyway. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
9478974680
commit
d53a820b37
17
files-reg.c
17
files-reg.c
@@ -84,29 +84,29 @@ static int open_remap_ghost(struct reg_file_info *rfi,
|
|||||||
return -1;
|
return -1;
|
||||||
gf->path = xmalloc(PATH_MAX);
|
gf->path = xmalloc(PATH_MAX);
|
||||||
if (!gf->path)
|
if (!gf->path)
|
||||||
return -1;
|
goto err;
|
||||||
|
|
||||||
ifd = open_image_ro(CR_FD_GHOST_FILE, rfe->remap_id);
|
ifd = open_image_ro(CR_FD_GHOST_FILE, rfe->remap_id);
|
||||||
if (ifd < 0)
|
if (ifd < 0)
|
||||||
return -1;
|
goto err;
|
||||||
|
|
||||||
if (read_img(ifd, &gfe) < 0)
|
if (read_img(ifd, &gfe) < 0)
|
||||||
return -1;
|
goto err;
|
||||||
|
|
||||||
snprintf(gf->path, PATH_MAX, "%s.cr.%x.ghost", rfi->path, rfe->remap_id);
|
snprintf(gf->path, PATH_MAX, "%s.cr.%x.ghost", rfi->path, rfe->remap_id);
|
||||||
gfd = open(gf->path, O_WRONLY | O_CREAT | O_EXCL, gfe.mode);
|
gfd = open(gf->path, O_WRONLY | O_CREAT | O_EXCL, gfe.mode);
|
||||||
if (gfd < 0) {
|
if (gfd < 0) {
|
||||||
pr_perror("Can't open ghost file");
|
pr_perror("Can't open ghost file");
|
||||||
return -1;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fchown(gfd, gfe.uid, gfe.gid) < 0) {
|
if (fchown(gfd, gfe.uid, gfe.gid) < 0) {
|
||||||
pr_perror("Can't reset user/group on ghost %#x\n", rfe->remap_id);
|
pr_perror("Can't reset user/group on ghost %#x\n", rfe->remap_id);
|
||||||
return -1;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_file(ifd, gfd, 0) < 0)
|
if (copy_file(ifd, gfd, 0) < 0)
|
||||||
return -1;
|
goto err;
|
||||||
|
|
||||||
close(ifd);
|
close(ifd);
|
||||||
close(gfd);
|
close(gfd);
|
||||||
@@ -116,6 +116,11 @@ static int open_remap_ghost(struct reg_file_info *rfi,
|
|||||||
gf_found:
|
gf_found:
|
||||||
rfi->remap_path = gf->path;
|
rfi->remap_path = gf->path;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err:
|
||||||
|
xfree(gf->path);
|
||||||
|
xfree(gf);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int collect_remaps(void)
|
static int collect_remaps(void)
|
||||||
|
Reference in New Issue
Block a user