Skip to content

Commit

Permalink
Btrfs: remove extent mapping if we fail to add chunk
Browse files Browse the repository at this point in the history
I got a double free error when unmounting a file system that failed to add a
chunk during its operation.  This is because we will kfree the mapping that
we created but leave the extent_map in the em_tree for chunks.  So to fix
this just remove the extent_map when we error out so we don't run into this
problem.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
  • Loading branch information
Josef Bacik committed Feb 20, 2013
1 parent 0448748 commit 0f5d42b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3821,9 +3821,10 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
write_lock(&em_tree->lock);
ret = add_extent_mapping(em_tree, em);
write_unlock(&em_tree->lock);
free_extent_map(em);
if (ret)
if (ret) {
free_extent_map(em);
goto error;
}

for (i = 0; i < map->num_stripes; ++i) {
struct btrfs_device *device;
Expand All @@ -3848,6 +3849,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
goto error_dev_extent;
}

free_extent_map(em);
kfree(devices_info);
return 0;

Expand All @@ -3863,6 +3865,14 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
break;
}
}
write_lock(&em_tree->lock);
remove_extent_mapping(em_tree, em);
write_unlock(&em_tree->lock);

/* One for our allocation */
free_extent_map(em);
/* One for the tree reference */
free_extent_map(em);
error:
kfree(map);
kfree(devices_info);
Expand Down

0 comments on commit 0f5d42b

Please sign in to comment.