Commit 5b7ff5b3c4468780b15c6b20cd0567cd9f2aa626

Authored by Tsutomu Itoh
Committed by Chris Mason
1 parent d79e50433b

Btrfs: fix memory leak in btrfs_quota_enable()

We should free quota_root before returning from the error
handling code.

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>

Showing 1 changed file with 13 additions and 4 deletions Side-by-side Diff

... ... @@ -790,8 +790,10 @@
790 790 }
791 791  
792 792 path = btrfs_alloc_path();
793   - if (!path)
794   - return -ENOMEM;
  793 + if (!path) {
  794 + ret = -ENOMEM;
  795 + goto out_free_root;
  796 + }
795 797  
796 798 key.objectid = 0;
797 799 key.type = BTRFS_QGROUP_STATUS_KEY;
... ... @@ -800,7 +802,7 @@
800 802 ret = btrfs_insert_empty_item(trans, quota_root, path, &key,
801 803 sizeof(*ptr));
802 804 if (ret)
803   - goto out;
  805 + goto out_free_path;
804 806  
805 807 leaf = path->nodes[0];
806 808 ptr = btrfs_item_ptr(leaf, path->slots[0],
807 809  
... ... @@ -818,8 +820,15 @@
818 820 fs_info->quota_root = quota_root;
819 821 fs_info->pending_quota_state = 1;
820 822 spin_unlock(&fs_info->qgroup_lock);
821   -out:
  823 +out_free_path:
822 824 btrfs_free_path(path);
  825 +out_free_root:
  826 + if (ret) {
  827 + free_extent_buffer(quota_root->node);
  828 + free_extent_buffer(quota_root->commit_root);
  829 + kfree(quota_root);
  830 + }
  831 +out:
823 832 return ret;
824 833 }
825 834