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.12.0-rc1~398 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=8ac478d0ad55edd322b2a4c6931e452d809bf5f3 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); }