Skip to content

Commit 9076bc4

Browse files
Jinjie Ruanshuahkh
authored andcommitted
kunit: Fix possible memory leak in kunit_filter_suites()
If both filter_glob and filters are not NULL, and kunit_parse_glob_filter() succeed, but kcalloc parsed_filters fails, the suite_glob and test_glob of parsed kzalloc in kunit_parse_glob_filter() will be leaked. As Rae suggested, assign -ENOMEM to *err to correctly free copy and goto free_parsed_glob to free the suite/test_glob of parsed. Fixes: 1c9fd08 ("kunit: fix uninitialized variables bug in attributes filtering") Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Suggested-by: Rae Moar <rmoar@google.com> Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 2b56a4b commit 9076bc4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/kunit/executor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ kunit_filter_suites(const struct kunit_suite_set *suite_set,
175175
filter_count = kunit_get_filter_count(filters);
176176
parsed_filters = kcalloc(filter_count, sizeof(*parsed_filters), GFP_KERNEL);
177177
if (!parsed_filters) {
178-
kfree(copy);
179-
return filtered;
178+
*err = -ENOMEM;
179+
goto free_parsed_glob;
180180
}
181181
for (j = 0; j < filter_count; j++)
182182
parsed_filters[j] = kunit_next_attr_filter(&filters, err);

0 commit comments

Comments
 (0)