btrfs-progs: plug a memory leak reported by cppcheck
authorKenji Okimoto <okimoto@clear-code.com>
Thu, 15 Nov 2012 04:47:50 +0000 (13:47 +0900)
committerDavid Sterba <dsterba@suse.cz>
Thu, 17 Jan 2013 17:27:55 +0000 (18:27 +0100)
[src/btrfs/disk-io.c:462]: (error) Memory leak: log_root

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
disk-io.c

index 03952051b5e25e0b67f0f910c84d93eb90de8480..32f45dcd1e5cfda572495bed229dd6cbf8314c7a 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -458,8 +458,10 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root,
        u64 blocknr = btrfs_super_log_root(disk_super);
        struct btrfs_root *log_root = malloc(sizeof(struct btrfs_root));
 
-       if (blocknr == 0)
+       if (blocknr == 0) {
+               free(log_root);
                return 0;
+       }
 
        blocksize = btrfs_level_size(tree_root,
                             btrfs_super_log_root_level(disk_super));
@@ -474,8 +476,12 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root,
 
        fs_info->log_root_tree = log_root;
 
-       if (!extent_buffer_uptodate(log_root->node))
+       if (!extent_buffer_uptodate(log_root->node)) {
+               free(log_root);
                return -EIO;
+       }
+
+       free(log_root);
        return 0;
 }