]> granicus.if.org Git - curl/commitdiff
cookies: fix leak when writing cookies to file
authorDaniel Gustafsson <daniel@yesql.se>
Sat, 8 Sep 2018 20:23:33 +0000 (22:23 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 10 Sep 2018 06:31:11 +0000 (08:31 +0200)
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

index 1668f02769eb3449f0b64a50356ad8b1d488a4b1..732ba9b835293510a90a5effee1693f457cef997 100644 (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);