All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jinjie Ruan <ruanjinjie@huawei.com>
To: <brendan.higgins@linux.dev>, <davidgow@google.com>,
	<skhan@linuxfoundation.org>, <jk@codeconstruct.com.au>,
	<dlatypov@google.com>, <rmoar@google.com>,
	<linux-kselftest@vger.kernel.org>, <kunit-dev@googlegroups.com>
Cc: <ruanjinjie@huawei.com>
Subject: [PATCH 4/4] kunit: Fix the wrong error path in kunit_filter_suites()
Date: Thu, 31 Aug 2023 15:16:55 +0800	[thread overview]
Message-ID: <20230831071655.2907683-5-ruanjinjie@huawei.com> (raw)
In-Reply-To: <20230831071655.2907683-1-ruanjinjie@huawei.com>

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;
 }
-- 
2.34.1


  parent reply	other threads:[~2023-08-31  7:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-31  7:16 [PATCH 0/4] kunit: Fix some bugs in kunit_filter_suites() Jinjie Ruan
2023-08-31  7:16 ` [PATCH 1/4] kunit: Fix wild-memory-access bug in kunit_free_suite_set() Jinjie Ruan
2023-08-31 20:29   ` Rae Moar
2023-09-01  5:17   ` David Gow
2023-08-31  7:16 ` [PATCH 2/4] kunit: Fix possible null-ptr-deref in kunit_parse_glob_filter() Jinjie Ruan
2023-08-31 20:34   ` Rae Moar
2023-09-01  5:18   ` David Gow
2023-08-31  7:16 ` [PATCH 3/4] kunit: Fix possible memory leak in kunit_filter_suites() Jinjie Ruan
2023-08-31 21:01   ` Rae Moar
2023-09-01  5:18   ` David Gow
2023-08-31  7:16 ` Jinjie Ruan [this message]
2023-08-31 21:03   ` [PATCH 4/4] kunit: Fix the wrong error path " Rae Moar
2023-09-01  5:18   ` David Gow
2023-09-03  6:37     ` Ruan Jinjie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230831071655.2907683-5-ruanjinjie@huawei.com \
    --to=ruanjinjie@huawei.com \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=jk@codeconstruct.com.au \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=rmoar@google.com \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.