]> git.ozlabs.org Git - ccan/blobdiff - ccan/opt/test/utils.c
various: make the _info License: wording uniform for GPL variants.
[ccan] / ccan / opt / test / utils.c
index 802b15381042b0dc63a26f440e54bb8c0f2b7f0c..9544fa77bd3493382c07e72f77f770d09b3d4cc7 100644 (file)
@@ -1,4 +1,4 @@
-#define _GNU_SOURCE
+#include "config.h"
 #include <ccan/tap/tap.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -29,7 +29,7 @@ void show_arg(char buf[OPT_SHOW_LEN], const char *arg)
 
 char *err_output = NULL;
 
-static void save_err_output(const char *fmt, ...)
+void save_err_output(const char *fmt, ...)
 {
        va_list ap;
        char *p;
@@ -49,7 +49,8 @@ static void save_err_output(const char *fmt, ...)
                err_output = p;
 }      
 
-/* FIXME: This leaks, BTW. */
+static bool allocated = false;
+
 bool parse_args(int *argc, char ***argv, ...)
 {
        char **a;
@@ -63,7 +64,12 @@ bool parse_args(int *argc, char ***argv, ...)
                (*argc)++;
                a = realloc(a, sizeof(*a) * (*argc + 1));
        }
+
+       if (allocated)
+               free(*argv);
+
        *argv = a;
+       allocated = true;
        /* Re-set before parsing. */
        optind = 0;