From 6e054623b462494c26bbaf46da7ba4b5f40ff285 Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Sat, 8 Sep 2018 22:23:33 +0200 Subject: cookies: fix leak when writing cookies to file If the formatting fails, we error out on a fatal error and clean up on the way out. The array was however freed within the wrong scope and was thus never freed in case the cookies were written to a file instead of STDOUT. Closes #2957 --- lib/cookie.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/cookie.c b/lib/cookie.c index 1668f0276..732ba9b83 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -1504,10 +1504,9 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere) format_ptr = get_netscape_format(array[i]); if(format_ptr == NULL) { fprintf(out, "#\n# Fatal libcurl error\n"); - if(!use_stdout) { - free(array); + free(array); + if(!use_stdout) fclose(out); - } return 1; } fprintf(out, "%s\n", format_ptr); -- cgit v1.2.3