Btrfs-progs: fix a small memory leak in btrfs-list.c
authorStefan Behrens <sbehrens@giantdisaster.de>
Tue, 9 Apr 2013 17:08:32 +0000 (19:08 +0200)
committerDavid Sterba <dsterba@suse.cz>
Tue, 23 Apr 2013 16:56:22 +0000 (18:56 +0200)
valgrind found this very obvious issue.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
btrfs-list.c

index a748d5e..38e7e53 100644 (file)
@@ -577,13 +577,13 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
 
                add_len = strlen(found->path);
 
-               /* room for / and for null */
-               tmp = malloc(add_len + 2 + len);
-               if (!tmp) {
-                       perror("malloc failed");
-                       exit(1);
-               }
                if (full_path) {
+                       /* room for / and for null */
+                       tmp = malloc(add_len + 2 + len);
+                       if (!tmp) {
+                               perror("malloc failed");
+                               exit(1);
+                       }
                        memcpy(tmp + add_len + 1, full_path, len);
                        tmp[add_len] = '/';
                        memcpy(tmp, found->path, add_len);