]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: fix memory leak in OOM in etags logic
authorDaniel Stenberg <daniel@haxx.se>
Thu, 12 Dec 2019 09:38:14 +0000 (10:38 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 12 Dec 2019 10:03:55 +0000 (11:03 +0100)
Detected by torture tests

Closes #4706

src/tool_operate.c

index bbd7fa49df55eb0127045e768b69ee4e2a0cbfce..d4f170e333829678e16be2fc517f84a747fcfa57 100644 (file)
@@ -926,25 +926,25 @@ static CURLcode single_transfer(struct GlobalConfig *global,
           /* open file for reading: */
           FILE *file = fopen(config->etag_compare_file, FOPEN_READTEXT);
           if(!file) {
-            warnf(
-              config->global,
-              "Failed to open %s\n", config->etag_compare_file);
-
+            errorf(config->global,
+                   "Failed to open %s\n", config->etag_compare_file);
             result = CURLE_READ_ERROR;
             break;
           }
 
           if((PARAM_OK == file2string(&etag_from_file, file)) &&
-             etag_from_file)
+             etag_from_file) {
             header = aprintf("If-None-Match: \"%s\"", etag_from_file);
+            Curl_safefree(etag_from_file);
+          }
           else
             header = aprintf("If-None-Match: \"\"");
 
           if(!header) {
-            warnf(
-              config->global,
-              "Failed to allocate memory for custom etag header\n");
-
+            if(file)
+              fclose(file);
+            errorf(config->global,
+                   "Failed to allocate memory for custom etag header\n");
             result = CURLE_OUT_OF_MEMORY;
             break;
           }
@@ -953,7 +953,6 @@ static CURLcode single_transfer(struct GlobalConfig *global,
           add2list(&config->headers, header);
 
           Curl_safefree(header);
-          Curl_safefree(etag_from_file);
 
           if(file) {
             fclose(file);