Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+16 -12
+16 -12
tools/testing/radix-tree/test.c
··· 29 29 return __radix_tree_insert(root, item->index, item->order, item); 30 30 } 31 31 32 - int item_insert(struct radix_tree_root *root, unsigned long index) 32 + struct item *item_create(unsigned long index, unsigned int order) 33 33 { 34 - return __item_insert(root, item_create(index, 0)); 34 + struct item *ret = malloc(sizeof(*ret)); 35 + 36 + ret->index = index; 37 + ret->order = order; 38 + return ret; 35 39 } 36 40 37 41 int item_insert_order(struct radix_tree_root *root, unsigned long index, 38 42 unsigned order) 39 43 { 40 - return __item_insert(root, item_create(index, order)); 44 + struct item *item = item_create(index, order); 45 + int err = __item_insert(root, item); 46 + if (err) 47 + free(item); 48 + return err; 49 + } 50 + 51 + int item_insert(struct radix_tree_root *root, unsigned long index) 52 + { 53 + return item_insert_order(root, index, 0); 41 54 } 42 55 43 56 void item_sanity(struct item *item, unsigned long index) ··· 72 59 return 1; 73 60 } 74 61 return 0; 75 - } 76 - 77 - struct item *item_create(unsigned long index, unsigned int order) 78 - { 79 - struct item *ret = malloc(sizeof(*ret)); 80 - 81 - ret->index = index; 82 - ret->order = order; 83 - return ret; 84 62 } 85 63 86 64 void item_check_present(struct radix_tree_root *root, unsigned long index)