[pseudo] [PATCH 2/7] pseudo_util: Avoid accidental free calls for without_libpseudo()

Richard Purdie <[email protected]> Wed, 1 Jul 2026 14:13:31 +0100
Newsgroups org.yoctoproject.lists.yocto-patches
Message-ID <[email protected]>
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 <[email protected]>
---
 pseudo_util.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/pseudo_util.c b/pseudo_util.c
index 2b0cc04..9cafad6 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -336,13 +336,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_diag("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;