Tests: fix: leak caused by misuse of realloc in multi-lib-test
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 11 Sep 2019 17:30:18 +0000 (13:30 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 11 Sep 2019 17:34:53 +0000 (13:34 -0400)
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 <jeremie.galarneau@efficios.com>
tests/regression/ust/multi-lib/multi-lib-test.c

index e145aa21aeae49e8310dc498c40e301499b88126..b5b2f314764af0ee5ff32706b1850fc464e34821 100644 (file)
@@ -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);
        }
 
This page took 0.031831 seconds and 4 git commands to generate.