[CRIU] [PATCH] irmap: don't leak irmap objects in --irmap-scan-path
Tycho Andersen
tycho.andersen at canonical.com
Mon Sep 28 08:00:30 PDT 2015
v2: use struct irmap directly in irmap_path_opt
Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
include/cr_options.h | 4 +++-
irmap.c | 22 ++++++++++------------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/include/cr_options.h b/include/cr_options.h
index af130dd..eac7283 100644
--- a/include/cr_options.h
+++ b/include/cr_options.h
@@ -38,9 +38,11 @@ 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..c0926e2 100644
--- a/irmap.c
+++ b/irmap.c
@@ -266,16 +266,7 @@ char *irmap_lookup(unsigned int s_dev, unsigned long i_ino)
* about them, hopefully they're more interesting than our hints.
*/
list_for_each_entry(o, &opts.irmap_scan_paths, node) {
- struct irmap *ir;
-
- ir = xzalloc(sizeof(*ir));
- if (!ir)
- goto out;
-
- ir->nr_kids = -1;
- ir->path = o->path;
-
- c = irmap_scan(ir, s_dev, i_ino);
+ c = irmap_scan(o->ir, s_dev, i_ino);
if (c) {
pr_debug("\tScanned %s\n", c->path);
path = c->path;
@@ -485,11 +476,18 @@ int irmap_scan_path_add(char *path)
{
struct irmap_path_opt *o;
- o = xmalloc(sizeof(*o));
+ o = xzalloc(sizeof(*o));
if (!o)
return -1;
- o->path = path;
+ o->ir = xzalloc(sizeof(*o->ir));
+ if (!o->ir) {
+ xfree(o);
+ return -1;
+ }
+
+ o->ir->path = path;
+ o->ir->nr_kids = -1;
list_add(&o->node, &opts.irmap_scan_paths);
return 0;
}
--
2.1.4
More information about the CRIU
mailing list