Fix possible memory leak in sourcing of environment file

Found by Coverity Scan

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2025-02-23 04:26:54 +01:00
1 parent 0c6f748f2c
commit 446f5bc8b8
1 file changed
+4 -11
+4 -11
View File
@@ -497,24 +497,17 @@ static void source_env(svc_t *svc)
continue; /* invalid key */
}
switch (wordexp(value, &we, 0)) {
case 0:
if (wordexp(value, &we, 0)) {
setenv(key, value, 1);
} else {
for (i = 0, *val = 0; i < we.we_wordc; i++) {
if (i > 0)
strlcat(val, " ", LINE_SIZE);
strlcat(val, we.we_wordv[i], LINE_SIZE);
}
setenv(key, val, 1);
wordfree(&we);
break;
case WRDE_NOSPACE:
wordfree(&we);
/* fallthrough */
default:
setenv(key, value, 1);
break;
}
wordfree(&we);
}
fclose(fp);