| From 7ffe97538c5dd1956852bbd265a8df5c2f8da24f Mon Sep 17 00:00:00 2001 |
| From: Filipe Manana <fdmanana@suse.com> |
| Date: Sat, 3 Aug 2019 09:53:16 +0100 |
| Subject: [PATCH] Btrfs: fix memory leaks in the test |
| test_find_first_clear_extent_bit |
| |
| commit cdf52bd9fe28d0ea93fb9f5d96ae59aec1148b69 upstream. |
| |
| The test creates an extent io tree and sets several ranges with the |
| CHUNK_ALLOCATED and CHUNK_TRIMMED bits, resulting in the allocation of |
| several extent state structures. However the test never clears those |
| ranges, resulting in memory leaks of the extent state structures. |
| |
| This is detected when CONFIG_BTRFS_DEBUG is set once we remove the |
| btrfs module (rmmod btrfs): |
| |
| [57399.787918] BTRFS: state leak: start 67108864 end 75497471 state 1 in tree 1 refs 1 |
| [57399.790155] BTRFS: state leak: start 33554432 end 67108863 state 33 in tree 1 refs 1 |
| [57399.791941] BTRFS: state leak: start 1048576 end 4194303 state 33 in tree 1 refs 1 |
| [57399.793753] BTRFS: state leak: start 67108864 end 75497471 state 1 in tree 1 refs 1 |
| [57399.795188] BTRFS: state leak: start 33554432 end 67108863 state 33 in tree 1 refs 1 |
| [57399.796453] BTRFS: state leak: start 1048576 end 4194303 state 33 in tree 1 refs 1 |
| [57399.797765] BTRFS: state leak: start 67108864 end 75497471 state 1 in tree 1 refs 1 |
| [57399.799049] BTRFS: state leak: start 33554432 end 67108863 state 33 in tree 1 refs 1 |
| [57399.800142] BTRFS: state leak: start 1048576 end 4194303 state 33 in tree 1 refs 1 |
| [57399.801126] BTRFS: state leak: start 67108864 end 75497471 state 1 in tree 1 refs 1 |
| [57399.802106] BTRFS: state leak: start 33554432 end 67108863 state 33 in tree 1 refs 1 |
| [57399.803119] BTRFS: state leak: start 1048576 end 4194303 state 33 in tree 1 refs 1 |
| [57399.804153] BTRFS: state leak: start 67108864 end 75497471 state 1 in tree 1 refs 1 |
| [57399.805196] BTRFS: state leak: start 33554432 end 67108863 state 33 in tree 1 refs 1 |
| [57399.806191] BTRFS: state leak: start 1048576 end 4194303 state 33 in tree 1 refs 1 |
| |
| The start and end offsets reported correspond exactly to the ranges |
| used by the test. |
| |
| So fix that by clearing all the ranges when the test finishes. |
| |
| Fixes: 1eaebb341d2b41 ("btrfs: Don't trim returned range based on input value in find_first_clear_extent_bit") |
| Signed-off-by: Filipe Manana <fdmanana@suse.com> |
| Signed-off-by: David Sterba <dsterba@suse.com> |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c |
| index a57213ec01c1..b9c7a92bd1cc 100644 |
| --- a/fs/btrfs/tests/extent-io-tests.c |
| +++ b/fs/btrfs/tests/extent-io-tests.c |
| @@ -536,6 +536,7 @@ static int test_find_first_clear_extent_bit(void) |
| |
| ret = 0; |
| out: |
| + clear_extent_bits(&tree, 0, (u64)-1, CHUNK_TRIMMED | CHUNK_ALLOCATED); |
| return ret; |
| } |
| |
| -- |
| 2.7.4 |
| |