]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cookie: remove the temporary file on (all) errors
authorDaniel Stenberg <daniel@haxx.se>
Tue, 28 Oct 2025 10:56:03 +0000 (11:56 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 28 Oct 2025 15:51:30 +0000 (16:51 +0100)
Fixes #19267
Reported-by: Harry Sintonen
Closes #19268

lib/cookie.c

index 9b89b7df70788e50ce960016c6672a97eb6220be..35b252971d9a9b8003ccc28ea58a4a87959922f2 100644 (file)
@@ -1595,7 +1595,6 @@ static CURLcode cookie_output(struct Curl_easy *data,
     curlx_fclose(out);
     out = NULL;
     if(tempstore && Curl_rename(tempstore, filename)) {
-      unlink(tempstore);
       error = CURLE_WRITE_ERROR;
       goto error;
     }
@@ -1612,7 +1611,10 @@ static CURLcode cookie_output(struct Curl_easy *data,
 error:
   if(out && !use_stdout)
     curlx_fclose(out);
-  free(tempstore);
+  if(tempstore) {
+    unlink(tempstore);
+    free(tempstore);
+  }
   return error;
 }