[CRIU] [PATCH] util: don't leak cr-img objects
Andrey Vagin
avagin at openvz.org
Tue Nov 17 23:54:57 PST 2015
From: Andrew Vagin <avagin at virtuozzo.com>
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
image.c | 2 ++
mount.c | 4 +++-
net.c | 13 +++++++------
3 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/image.c b/image.c
index dc9d6a1..342971b 100644
--- a/image.c
+++ b/image.c
@@ -369,6 +369,8 @@ int open_image_lazy(struct cr_img *img)
void close_image(struct cr_img *img)
{
+ if (!img)
+ return;
if (lazy_image(img)) {
/*
* Remove the image file if it's there so that
diff --git a/mount.c b/mount.c
index 562d6ca..03544dd 100644
--- a/mount.c
+++ b/mount.c
@@ -1250,8 +1250,10 @@ 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 || 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 bfdebad..45c8318 100644
--- a/net.c
+++ b/net.c
@@ -726,16 +726,17 @@ err_free:
static int restore_ip_dump(int type, int pid, char *cmd)
{
- int ret = -1;
+ int ret = 0;
struct cr_img *img;
img = open_image(type, O_RSTR, pid);
- if (empty_image(img))
- return 0;
- if (img) {
+ if (img == NULL)
+ return -1;
+
+ if (!empty_image(img))
ret = run_ip_tool(cmd, "restore", NULL, img_raw_fd(img), -1, 0);
- close_image(img);
- }
+
+ close_image(img);
return ret;
}
--
2.4.3
More information about the CRIU
mailing list