summaryrefslogtreecommitdiff
path: root/volumes.c
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@gmail.com>2013-06-26 17:41:36 +0100
committerChris Mason <chris.mason@fusionio.com>2013-07-05 10:01:04 -0400
commit4fbfcaa8beb901050612bc35a0c8bbc1f3b58188 (patch)
tree53b1e3d3f4c0ae5c298587a11101d10d592119fe /volumes.c
parent0bae08fdab01078bbc514be10319f87f552c4787 (diff)
downloadbtrfs-progs-4fbfcaa8beb901050612bc35a0c8bbc1f3b58188.tar.gz
Btrfs-progs: fix closing of devices
If a device could not be opened in volumes.c:read_one_dev(), a btrfs_device instance was allocated and added to the list of devices of the fs - however this device instance had its fd, name and label fields not initialized. This is problematic in disk-io.c:close_all_devices() as it tried to sync, fadvise and close the (invalid) fd of the device, and kfree() its name and label, which pointed to random memory locations. Thread 1 (Thread 0x7f0a3d2d1740 (LWP 23585)): #0 __GI___libc_free (mem=0xa5a5a5a5a5a5a5a5) at malloc.c:2970 #1 0x000000000042054b in close_all_devices (fs_info=0x1e92bf0) at disk-io.c:1276 #2 0x0000000000421dcd in close_ctree (root=<optimized out>) at disk-io.c:1336 #3 0x0000000000418cfa in cmd_check (argc=<optimized out>, argv=<optimized out>) at cmds-check.c:4171 #4 0x0000000000403ed4 in main (argc=2, argv=0x7fff9a583d28) at btrfs.c:295 v2: Added Liu Bo's review mention. Reviewed-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'volumes.c')
-rw-r--r--volumes.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/volumes.c b/volumes.c
index 437e219..0ff2283 100644
--- a/volumes.c
+++ b/volumes.c
@@ -1631,10 +1631,10 @@ static int read_one_dev(struct btrfs_root *root,
if (!device) {
printk("warning devid %llu not found already\n",
(unsigned long long)devid);
- device = kmalloc(sizeof(*device), GFP_NOFS);
+ device = kzalloc(sizeof(*device), GFP_NOFS);
if (!device)
return -ENOMEM;
- device->total_ios = 0;
+ device->fd = -1;
list_add(&device->dev_list,
&root->fs_info->fs_devices->devices);
}