pipecmd: fix minor memleak detected by scan-build.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 8 Sep 2016 02:00:08 +0000 (11:30 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 8 Sep 2016 02:00:08 +0000 (11:30 +0930)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/pipecmd/pipecmd.c

index 42c6689445876e5b832520bd55a1e1aecf288c43..e8aec15b4e7f62993489de618a445439ac06c8c7 100644 (file)
@@ -16,9 +16,12 @@ static char **gather_args(const char *arg0, va_list ap)
        arr[0] = (char *)arg0;
 
        while ((arr[n++] = va_arg(ap, char *)) != NULL) {
        arr[0] = (char *)arg0;
 
        while ((arr[n++] = va_arg(ap, char *)) != NULL) {
-               arr = realloc(arr, sizeof(char *) * (n + 1));
-               if (!arr)
+               char **narr = realloc(arr, sizeof(char *) * (n + 1));
+               if (!narr) {
+                       free(arr);
                        return NULL;
                        return NULL;
+               }
+               arr = narr;
        }
        return arr;
 }
        }
        return arr;
 }