From: Daniel Gustafsson Date: Sat, 8 Sep 2018 20:23:33 +0000 (+0200) Subject: cookies: fix leak when writing cookies to file X-Git-Tag: curl-7_62_0~204 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6e054623b462494c26bbaf46da7ba4b5f40ff285;p=thirdparty%2Fcurl.git 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 --- diff --git a/lib/cookie.c b/lib/cookie.c index 1668f02769..732ba9b835 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);