diff mbox series

[pseudo,v2,16/23] pseudo_util: Avoid accidental free calls for without_libpseudo()

Message ID 1783104055-19005-17-git-send-email-mark.hatle@kernel.crashing.org
State New
Headers show
Series Create new pseudo 1.99.0 version | expand

Commit Message

Mark Hatle July 3, 2026, 6:40 p.m. UTC
From: Richard Purdie <richard.purdie@linuxfoundation.org>

We need to return list after the strdup otherwise the caller doesn't
know whether to free the return value or not.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Message-ID: <20260701131336.3578279-2-richard.purdie@linuxfoundation.org>
Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org>
---
 pseudo_util.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/pseudo_util.c b/pseudo_util.c
index 3eaa9e6..66afe25 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -346,13 +346,13 @@  without_libpseudo(char *list) {
 	if (list[0] == '=' || list[0] == PSEUDO_LINKPATH_SEPARATOR[0])
 		skip_start = 1;
 
-	if ((*real_regexec)(&libpseudo_regex, list, 1, pmatch, 0)) {
-		return list;
-	}
 	list = strdup(list);
 	if (!list) {
 		pseudo_error("Couldn't allocate memory to remove libpseudo from environment.\n");
 	}
+	if ((*real_regexec)(&libpseudo_regex, list, 1, pmatch, 0)) {
+		return list;
+	}
 	while (list && !(*real_regexec)(&libpseudo_regex, list, 1, pmatch, 0)) {
 		char *start = list + pmatch[0].rm_so;
 		char *end = list + pmatch[0].rm_eo;