X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fopt%2Ftest%2Futils.c;h=9544fa77bd3493382c07e72f77f770d09b3d4cc7;hb=c2d60644d2c00fb32258b380bb25ce0a26b87026;hp=802b15381042b0dc63a26f440e54bb8c0f2b7f0c;hpb=3fb6b6be5a395fbe293e61339e6be67118234508;p=ccan diff --git a/ccan/opt/test/utils.c b/ccan/opt/test/utils.c index 802b1538..9544fa77 100644 --- a/ccan/opt/test/utils.c +++ b/ccan/opt/test/utils.c @@ -1,4 +1,4 @@ -#define _GNU_SOURCE +#include "config.h" #include #include #include @@ -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;