1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-23 16:48:49 -05:00

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
This commit is contained in:
Daniel Gustafsson 2018-09-08 22:23:33 +02:00 committed by Daniel Stenberg
parent c3654df166
commit 6e054623b4
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -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);