From: Jérémie Galarneau Date: Wed, 11 Sep 2019 17:30:18 +0000 (-0400) Subject: Tests: fix: leak caused by misuse of realloc in multi-lib-test X-Git-Tag: v2.11.0-rc4~51 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=5c0fcac1950bdfa9a2c3f84917dd9be056f4bced;p=lttng-tools.git Tests: fix: leak caused by misuse of realloc in multi-lib-test realloc() can return NULL, in which case 'libraries' will never be free'd in the case where the reallocation happens outside of the while()'s first iteration. Signed-off-by: Jérémie Galarneau --- diff --git a/tests/regression/ust/multi-lib/multi-lib-test.c b/tests/regression/ust/multi-lib/multi-lib-test.c index e145aa21a..b5b2f3147 100644 --- a/tests/regression/ust/multi-lib/multi-lib-test.c +++ b/tests/regression/ust/multi-lib/multi-lib-test.c @@ -201,12 +201,15 @@ int main(int argc, const char **argv) * Populate the libraries array with the arguments passed to the process. */ while (poptPeekArg(optCon) != NULL) { + char **realloced_libraries = NULL; + nb_libraries++; - libraries = realloc(libraries, nb_libraries * sizeof(char *)); - if (!libraries) { + realloced_libraries = realloc(libraries, nb_libraries * sizeof(char *)); + if (!realloced_libraries) { ret = -1; goto error; } + libraries = realloced_libraries; libraries[nb_libraries - 1] = (char *) poptGetArg(optCon); }