[CRIU] [PATCH] util: don't leak cr-img objects (v2)

Andrey Vagin avagin at openvz.org
Tue Nov 24 04:33:32 PST 2015


From: Andrew Vagin <avagin at virtuozzo.com>

We need to call close_image() for "empty" images.

v2: don't touch generic functiuons
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 mount.c | 6 +++++-
 net.c   | 4 +++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/mount.c b/mount.c
index 562d6ca..20ae79b 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 d719471..51b3159 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);
-- 
2.4.3



More information about the CRIU mailing list