From 49448676acd36bb887329ef47351ffd79e841d2e Mon Sep 17 00:00:00 2001 From: Andrew Vagin Date: Tue, 24 Nov 2015 15:33:00 +0300 Subject: [PATCH] util: don't leak cr-img objects (v2) We need to call close_image() for "empty" images. v2: don't touch generic functiuons Signed-off-by: Andrew Vagin Signed-off-by: Pavel Emelyanov --- mount.c | 6 +++++- net.c | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mount.c b/mount.c index 562d6ca5c..20ae79b89 100644 --- a/mount.c +++ b/mount.c @@ -1250,8 +1250,12 @@ static int tmpfs_restore(struct mount_info *pm) close_image(img); img = open_image(CR_FD_TMPFS_IMG, O_RSTR, pm->mnt_id); } - if (!img || empty_image(img)) + if (!img) return -1; + if (empty_image(img)) { + close_image(img); + return -1; + } ret = cr_system(img_raw_fd(img), -1, -1, "tar", (char *[]) {"tar", "--extract", "--gzip", diff --git a/net.c b/net.c index d719471d9..51b31597a 100644 --- a/net.c +++ b/net.c @@ -729,8 +729,10 @@ static int restore_ip_dump(int type, int pid, char *cmd) struct cr_img *img; img = open_image(type, O_RSTR, pid); - if (empty_image(img)) + if (empty_image(img)) { + close_image(img); return 0; + } if (img) { ret = run_ip_tool(cmd, "restore", NULL, img_raw_fd(img), -1, 0); close_image(img);