]> granicus.if.org Git - curl/commitdiff
tool_cb_hdr: handle failure of rename()
authorKamil Dudka <kdudka@redhat.com>
Mon, 15 Oct 2018 14:03:46 +0000 (16:03 +0200)
committerKamil Dudka <kdudka@redhat.com>
Wed, 17 Oct 2018 07:15:05 +0000 (09:15 +0200)
Detected by Coverity.

Closes #3140
Reviewed-by: Jay Satiro
src/tool_cb_hdr.c

index 983258cee38d42fea898872c5a55f545bcab71e3..7a7a836c4a45e322b9d3d726f2fa9b848bea49ae 100644 (file)
@@ -132,15 +132,24 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
       filename = parse_filename(p, len);
       if(filename) {
         if(outs->stream) {
+          int rc;
           /* already opened and possibly written to */
           if(outs->fopened)
             fclose(outs->stream);
           outs->stream = NULL;
 
           /* rename the initial file name to the new file name */
-          rename(outs->filename, filename);
+          rc = rename(outs->filename, filename);
+          if(rc != 0) {
+            warnf(outs->config->global, "Failed to rename %s -> %s: %s\n",
+                  outs->filename, filename, strerror(errno));
+          }
           if(outs->alloc_filename)
-            free(outs->filename);
+            Curl_safefree(outs->filename);
+          if(rc != 0) {
+            free(filename);
+            return failure;
+          }
         }
         outs->is_cd_filename = TRUE;
         outs->s_isreg = TRUE;