aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gustafsson <daniel@yesql.se>2018-09-08 22:23:33 +0200
committerDaniel Stenberg <daniel@haxx.se>2018-09-10 08:31:11 +0200
commit6e054623b462494c26bbaf46da7ba4b5f40ff285 (patch)
tree09d65fb4edf1865efde0953a9aa7e9e04ade8fc8
parentc3654df166ff9bded751809af4ce6a3b1d7b0f81 (diff)
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
-rw-r--r--lib/cookie.c5
1 files 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);