X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fopt%2Ftest%2Futils.c;h=9544fa77bd3493382c07e72f77f770d09b3d4cc7;hp=fa0a2022e0987368e398161bbce28d60fd43b028;hb=6fa62e5ae1e29646aa718e99020fdf2efee74373;hpb=e34192d580958aaffff3754a4e2bf1eccbb489f8 diff --git a/ccan/opt/test/utils.c b/ccan/opt/test/utils.c index fa0a2022..9544fa77 100644 --- a/ccan/opt/test/utils.c +++ b/ccan/opt/test/utils.c @@ -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;