Skip to content

Commit bb21e3f

Browse files
committed
testsuite: Prefer _cleanup_free_ to free temp storage
`preload` is freed in all exit paths, just use _cleanup_free_ to avoid bugs like the one fixed in commit e1d21ab ("testsuite: Fix memory leak in test_export_environ error paths") Signed-off-by: Lucas De Marchi <demarchi@kernel.org> Link: #423
1 parent a88a859 commit bb21e3f

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

testsuite/testsuite.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ int test_spawn_prog(const char *prog, const char *const args[])
168168

169169
static void test_export_environ(const struct test *t)
170170
{
171-
char *preload = NULL;
171+
_cleanup_free_ char *preload = NULL;
172172
size_t preloadlen = 0;
173173
size_t i;
174174
const struct keyval *env;
@@ -188,7 +188,6 @@ static void test_export_environ(const struct test *t)
188188
tmp = realloc(preload, preloadlen + 2 + ldpreloadlen);
189189
if (tmp == NULL) {
190190
ERR("oom: test_export_environ()\n");
191-
free(preload);
192191
return;
193192
}
194193
preload = tmp;
@@ -209,7 +208,6 @@ static void test_export_environ(const struct test *t)
209208
tmp = malloc(preloadlen + 2 + len);
210209
if (tmp == NULL) {
211210
ERR("oom: test_export_environ()\n");
212-
free(preload);
213211
return;
214212
}
215213
memcpy(tmp, existing_preload, len);
@@ -223,8 +221,6 @@ static void test_export_environ(const struct test *t)
223221
setenv("LD_PRELOAD", preload, 1);
224222
}
225223

226-
free(preload);
227-
228224
for (env = t->env_vars; env && env->key; env++)
229225
setenv(env->key, env->val, 1);
230226
}

0 commit comments

Comments
 (0)