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>
* 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);
}