[CRIU] [PATCH 6b/16] restore: release all previous entries from the vma list

Andrey Vagin avagin at openvz.org
Tue Nov 20 10:58:17 EST 2012


Before the vma list was always empty, but it will be changed.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-restore.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index 16e93ee..e5caf54 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -178,17 +178,19 @@ err:
 
 static int read_vmas(int pid, struct list_head *vmas, int *nr_vmas)
 {
-	int fd, ret = -1;
+	int fd, ret = 0;
+	LIST_HEAD(old);
+	struct vma_area *vma;
 
 	*nr_vmas = 0;
+	list_replace_init(vmas, &old);
 
 	/* Skip errors, because a zombie doesn't have an image of vmas */
 	fd = open_image_ro(CR_FD_VMAS, pid);
 	if (fd < 0) {
-		if (errno == ENOENT)
-			return 0;
-		else
-			return fd;
+		if (errno != ENOENT)
+			ret = fd;
+		goto out;
 	}
 
 	while (1) {
@@ -219,6 +221,14 @@ static int read_vmas(int pid, struct list_head *vmas, int *nr_vmas)
 	}
 
 	close(fd);
+
+out:
+	while (!list_empty(&old)) {
+		vma = list_first_entry(&old, struct vma_area, list);
+		list_del(&vma->list);
+		xfree(vma);
+	}
+
 	return ret;
 }
 
-- 
1.7.11.7



More information about the CRIU mailing list