Take the last kfree(parsed_filters) and add it to be the first. Take the first kfree(copy) and add it to be the last. The Best practice is to return these errors reversely.
Fixes: 529534e8cba3 ("kunit: Add ability to filter attributes") Fixes: abbf73816b6f ("kunit: fix possible memory leak in kunit_filter_suites()") Signed-off-by: Jinjie Ruan ruanjinjie@huawei.com --- lib/kunit/executor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c index 7654c09c1ab1..da9444d22711 100644 --- a/lib/kunit/executor.c +++ b/lib/kunit/executor.c @@ -229,16 +229,16 @@ kunit_filter_suites(const struct kunit_suite_set *suite_set, filtered.end = copy;
err: - if (*err) - kfree(copy); + if (filter_count) + kfree(parsed_filters);
if (filter_glob) { kfree(parsed_glob.suite_glob); kfree(parsed_glob.test_glob); }
- if (filter_count) - kfree(parsed_filters); + if (*err) + kfree(copy);
return filtered; }