diff mbox series

[3/4] kunit: Fix possible memory leak in kunit_filter_suites()

Message ID 20230831071655.2907683-4-ruanjinjie@huawei.com
State New
Headers show
Series [1/4] kunit: Fix wild-memory-access bug in kunit_free_suite_set() | expand

Commit Message

Jinjie Ruan Aug. 31, 2023, 7:16 a.m. UTC
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.

Fixes: 1c9fd080dffe ("kunit: fix uninitialized variables bug in attributes filtering")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 lib/kunit/executor.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c
index 25ce8d6e5fe7..7654c09c1ab1 100644
--- a/lib/kunit/executor.c
+++ b/lib/kunit/executor.c
@@ -176,10 +176,8 @@  kunit_filter_suites(const struct kunit_suite_set *suite_set,
 	if (filters) {
 		filter_count = kunit_get_filter_count(filters);
 		parsed_filters = kcalloc(filter_count, sizeof(*parsed_filters), GFP_KERNEL);
-		if (!parsed_filters) {
-			kfree(copy);
-			return filtered;
-		}
+		if (!parsed_filters)
+			goto err;
 		for (j = 0; j < filter_count; j++)
 			parsed_filters[j] = kunit_next_attr_filter(&filters, err);
 		if (*err)