aboutsummaryrefslogtreecommitdiffstats
path: root/disk-io.c
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fusionio.com>2013-03-18 11:07:03 -0400
committerDavid Sterba <dsterba@suse.cz>2013-03-18 19:44:32 +0100
commit87c09f70b5e334f68cc19c0514d412f666b4eb14 (patch)
treee2ffc811284807caf2a18ae20018db716e8b7196 /disk-io.c
parente9393c220f45f8501d7c0c94e83f99fc91273272 (diff)
downloadbtrfs-progs-87c09f70b5e334f68cc19c0514d412f666b4eb14.tar.gz
btrfs-progs-87c09f70b5e334f68cc19c0514d412f666b4eb14.tar.xz
btrfs-progs-87c09f70b5e334f68cc19c0514d412f666b4eb14.zip
Btrfs-progs: fix memory leaks on cleanup
I've been working on btrfs-image and I kept seeing these leaks pop up on valgrind so I'm just fixing them. We don't properly cleanup the device cache, the chunk tree mapping cache, or the space infos on close. With this patch valgrind doesn't complain about any memory leaks running btrfs-image. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'disk-io.c')
-rw-r--r--disk-io.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/disk-io.c b/disk-io.c
index 6ef35bb..be4abb8 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1278,24 +1278,39 @@ int write_ctree_super(struct btrfs_trans_handle *trans,
static int close_all_devices(struct btrfs_fs_info *fs_info)
{
struct list_head *list;
- struct list_head *next;
struct btrfs_device *device;
- return 0;
-
list = &fs_info->fs_devices->devices;
- list_for_each(next, list) {
- device = list_entry(next, struct btrfs_device, dev_list);
+ while (!list_empty(list)) {
+ device = list_entry(list->next, struct btrfs_device, dev_list);
+ list_del_init(&device->dev_list);
if (device->fd) {
fsync(device->fd);
if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
fprintf(stderr, "Warning, could not drop caches\n");
}
close(device->fd);
+ kfree(device->name);
+ kfree(device->label);
+ kfree(device);
}
+ kfree(fs_info->fs_devices);
return 0;
}
+static void free_mapping_cache(struct btrfs_fs_info *fs_info)
+{
+ struct cache_tree *cache_tree = &fs_info->mapping_tree.cache_tree;
+ struct cache_extent *ce;
+ struct map_lookup *map;
+
+ while ((ce = find_first_cache_extent(cache_tree, 0))) {
+ map = container_of(ce, struct map_lookup, ce);
+ remove_cache_extent(cache_tree, ce);
+ kfree(map);
+ }
+}
+
int close_ctree(struct btrfs_root *root)
{
int ret;
@@ -1336,6 +1351,7 @@ int close_ctree(struct btrfs_root *root)
}
close_all_devices(fs_info);
+ free_mapping_cache(fs_info);
extent_io_tree_cleanup(&fs_info->extent_cache);
extent_io_tree_cleanup(&fs_info->free_space_cache);
extent_io_tree_cleanup(&fs_info->block_group_cache);