]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Btrfs: fix memory leak of log roots
authorLiu Bo <bo.li.liu@oracle.com>
Wed, 27 Feb 2013 13:28:24 +0000 (13:28 +0000)
committerJosef Bacik <jbacik@fusionio.com>
Thu, 28 Feb 2013 18:33:51 +0000 (13:33 -0500)
When we abort a transaction while fsyncing, we'll skip freeing log roots
part of committing a transaction, which leads to memory leak.

This adds a 'free log roots' in putting super when no more users hold
references on log roots, so it's safe and clean.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
fs/btrfs/disk-io.c
fs/btrfs/tree-log.c

index eb7c1430852106034fac0848ee3b5ff8a3903624..5031e6dd5938a967166c1c30e398902c88cd2134 100644 (file)
@@ -3253,6 +3253,11 @@ void btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root)
        if (btrfs_root_refs(&root->root_item) == 0)
                synchronize_srcu(&fs_info->subvol_srcu);
 
+       if (fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) {
+               btrfs_free_log(NULL, root);
+               btrfs_free_log_root_tree(NULL, fs_info);
+       }
+
        __btrfs_remove_free_space_cache(root->free_ino_pinned);
        __btrfs_remove_free_space_cache(root->free_ino_ctl);
        free_fs_root(root);
index e8b7a68e1b37a15a5d853f57431a4f3ab97f5582..8e85e0e4333d4b1a4b74e0ebe9f163904a90ac48 100644 (file)
@@ -2466,8 +2466,10 @@ static void free_log_tree(struct btrfs_trans_handle *trans,
                .process_func = process_one_buffer
        };
 
-       ret = walk_log_tree(trans, log, &wc);
-       BUG_ON(ret);
+       if (trans) {
+               ret = walk_log_tree(trans, log, &wc);
+               BUG_ON(ret);
+       }
 
        while (1) {
                ret = find_first_extent_bit(&log->dirty_log_pages,