diff options
author | Matthew Wilcox <mawilcox@microsoft.com> | 2017-01-29 07:48:34 +0100 |
---|---|---|
committer | Matthew Wilcox <mawilcox@microsoft.com> | 2017-02-14 03:44:06 +0100 |
commit | 18d0c57394e42ff536e5fdc776b6b217fdd9889c (patch) | |
tree | 905864b7e31e039ba324cd3a354f0c1fc9527cf9 /tools/testing | |
parent | radix tree test suite: Enable address sanitizer (diff) | |
download | linux-18d0c57394e42ff536e5fdc776b6b217fdd9889c.tar.xz linux-18d0c57394e42ff536e5fdc776b6b217fdd9889c.zip |
radix tree test suite: Fix leaky tests
If item_insert() or item_insert_order() failed to insert an item, they
would leak the item they had just created. This was causing runaway
memory consumption while running the iteration_check testcase, which
proves that Ross has too much memory in his workstation ;-)
Make sure to free the item on error. Found with -fsanitize=address.
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Reviewed-by: Rehas Sachdeva <aquannie@gmail.com>
Diffstat (limited to 'tools/testing')
-rw-r--r-- | tools/testing/radix-tree/test.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/tools/testing/radix-tree/test.c b/tools/testing/radix-tree/test.c index e5726e373646..1a257d738a1e 100644 --- a/tools/testing/radix-tree/test.c +++ b/tools/testing/radix-tree/test.c @@ -29,15 +29,28 @@ int __item_insert(struct radix_tree_root *root, struct item *item) return __radix_tree_insert(root, item->index, item->order, item); } -int item_insert(struct radix_tree_root *root, unsigned long index) +struct item *item_create(unsigned long index, unsigned int order) { - return __item_insert(root, item_create(index, 0)); + struct item *ret = malloc(sizeof(*ret)); + + ret->index = index; + ret->order = order; + return ret; } int item_insert_order(struct radix_tree_root *root, unsigned long index, unsigned order) { - return __item_insert(root, item_create(index, order)); + struct item *item = item_create(index, order); + int err = __item_insert(root, item); + if (err) + free(item); + return err; +} + +int item_insert(struct radix_tree_root *root, unsigned long index) +{ + return item_insert_order(root, index, 0); } void item_sanity(struct item *item, unsigned long index) @@ -61,15 +74,6 @@ int item_delete(struct radix_tree_root *root, unsigned long index) return 0; } -struct item *item_create(unsigned long index, unsigned int order) -{ - struct item *ret = malloc(sizeof(*ret)); - - ret->index = index; - ret->order = order; - return ret; -} - void item_check_present(struct radix_tree_root *root, unsigned long index) { struct item *item; |