diff --git a/src/option.c b/src/option.c index 1ba8335..274732f 100644 --- a/src/option.c +++ b/src/option.c @@ -6270,7 +6270,11 @@ void read_opts(int argc, char **argv, char *compile_opts) if ((token = strtok(NULL, " \t\n\r")) && (daemon->domain_suffix = canonicalise_opt(token))) - break; + { + /* We don't call get_line_alloc() until it returns false and frees the automatically */ + get_line_alloc(NULL, &line, &linesz); + break; + } } fclose(f); diff --git a/src/util.c b/src/util.c index 029223b..3d8ed40 100644 --- a/src/util.c +++ b/src/util.c @@ -1038,16 +1038,15 @@ void free_real(const char *func, unsigned int line, void *ptr) } /* get lines from f, expand buffer as required. Buffer is freed when - EOF reached and we return zero. */ + EOF reached and we return zero. Buffer also freed if f == NULL. */ int get_line_alloc(FILE *f, char **buffp, size_t *sizep) { - int c; size_t cnt = 0; char *buff = *buffp; - - while (1) { - c = getc(f); + while (1) { + int c = f ? getc(f) : EOF; + if (cnt == *sizep) { void *new; @@ -1081,6 +1080,8 @@ int get_line_alloc(FILE *f, char **buffp, size_t *sizep) return 1; free(buff); + *buffp = NULL; + *sizep = 0; return 0; }