[CRIU] [PATCH] irmap: don't leak irmap objects in --irmap-scan-path

Tycho Andersen tycho.andersen at canonical.com
Mon Sep 21 09:22:09 PDT 2015


Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 include/cr_options.h |  3 +++
 irmap.c              | 13 +++++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/include/cr_options.h b/include/cr_options.h
index af130dd..a97307b 100644
--- a/include/cr_options.h
+++ b/include/cr_options.h
@@ -38,9 +38,12 @@ struct cg_root_opt {
  */
 #define DEFAULT_GHOST_LIMIT	(1 << 20)
 
+struct irmap;
+
 struct irmap_path_opt {
 	struct list_head node;
 	char *path;
+	struct irmap *ir;
 };
 
 struct cr_options {
diff --git a/irmap.c b/irmap.c
index d0577b8..c0fc89e 100644
--- a/irmap.c
+++ b/irmap.c
@@ -268,9 +268,14 @@ char *irmap_lookup(unsigned int s_dev, unsigned long i_ino)
 	list_for_each_entry(o, &opts.irmap_scan_paths, node) {
 		struct irmap *ir;
 
-		ir = xzalloc(sizeof(*ir));
-		if (!ir)
-			goto out;
+		if (!o->ir) {
+			ir = xzalloc(sizeof(*ir));
+			if (!ir)
+				goto out;
+			o->ir = ir;
+		} else {
+			ir = o->ir;
+		}
 
 		ir->nr_kids = -1;
 		ir->path = o->path;
@@ -485,7 +490,7 @@ int irmap_scan_path_add(char *path)
 {
 	struct irmap_path_opt *o;
 
-	o = xmalloc(sizeof(*o));
+	o = xzalloc(sizeof(*o));
 	if (!o)
 		return -1;
 
-- 
2.1.4



More information about the CRIU mailing list