btrfs-progs: mkfs seg fault for wrong free
authorAnand Jain <anand.jain@oracle.com>
Fri, 26 Apr 2013 02:44:45 +0000 (10:44 +0800)
committerChris Mason <chris.mason@fusionio.com>
Fri, 3 May 2013 02:30:02 +0000 (22:30 -0400)
With commit
        87c09f7 Btrfs-progs: fix memory leaks on cleanup

mkfs on multiple dev is ending with segfault at
close_all_devices() during kfree(device->name)

because mkfs calls btrfs_add_to_fsid, which does not initialize
name when dev is added to the list.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
utils.c

diff --git a/utils.c b/utils.c
index 412de80..7b4cd74 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -482,7 +482,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
        u64 num_devs;
        int ret;
 
-       device = kmalloc(sizeof(*device), GFP_NOFS);
+       device = kzalloc(sizeof(*device), GFP_NOFS);
        if (!device)
                return -ENOMEM;
        buf = kmalloc(sectorsize, GFP_NOFS);