]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool: move the error buffer to the per transfer struct
authorDaniel Stenberg <daniel@haxx.se>
Sun, 31 Aug 2025 14:24:44 +0000 (16:24 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 1 Sep 2025 06:52:57 +0000 (08:52 +0200)
To avoid having to alloc or manage it separately.

Closes #18442

src/config2setopts.c
src/tool_operate.c
src/tool_operate.h
src/tool_writeout.c

index ba31de9abfd64f863861ec56bf983af0f671402c..e8f4b0a407aec7d8f55e9f549ee2146982e8bf14 100644 (file)
@@ -40,9 +40,6 @@
 
 #define BUFFER_SIZE 102400L
 
-/* When doing serial transfers, we use a single fixed error area */
-static char global_errorbuffer[CURL_ERROR_SIZE];
-
 #ifdef IP_TOS
 static int get_address_family(curl_socket_t sockfd)
 {
@@ -869,10 +866,7 @@ CURLcode config2setopts(struct OperationConfig *config,
   my_setopt_str(curl, CURLOPT_LOGIN_OPTIONS, config->login_options);
   my_setopt_str(curl, CURLOPT_USERPWD, config->userpwd);
   my_setopt_str(curl, CURLOPT_RANGE, config->range);
-  if(!global->parallel) {
-    per->errorbuffer = global_errorbuffer;
-    my_setopt(curl, CURLOPT_ERRORBUFFER, global_errorbuffer);
-  }
+  my_setopt(curl, CURLOPT_ERRORBUFFER, per->errorbuffer);
   my_setopt_long(curl, CURLOPT_TIMEOUT_MS, config->timeout_ms);
 
   switch(config->httpreq) {
index 57d9e9d3bd4ac765fd69c2d09c70d12ea0dd18d8..e58b7bd0757a7d0021e8d84bf7b0e81a8098542e 100644 (file)
@@ -582,7 +582,7 @@ static CURLcode post_per_transfer(struct per_transfer *per,
        (!global->silent || global->showerror)) {
       const char *msg = per->errorbuffer;
       fprintf(tool_stderr, "curl: (%d) %s\n", result,
-              (msg && msg[0]) ? msg : curl_easy_strerror(result));
+              msg[0] ? msg : curl_easy_strerror(result));
       if(result == CURLE_PEER_FAILED_VERIFICATION)
         fputs(CURL_CA_CERT_ERRORMSG, tool_stderr);
     }
@@ -705,8 +705,6 @@ skip:
   free(per->url);
   free(per->outfile);
   free(per->uploadfile);
-  if(global->parallel)
-    free(per->errorbuffer);
   curl_slist_free_all(per->hdrcbdata.headlist);
   per->hdrcbdata.headlist = NULL;
   return result;
@@ -1346,7 +1344,6 @@ static CURLcode add_parallel_transfers(CURLM *multi, CURLSH *share,
   CURLcode result = CURLE_OK;
   CURLMcode mcode;
   bool sleeping = FALSE;
-  char *errorbuf;
   curl_off_t nxfers;
 
   *addedp = FALSE;
@@ -1381,10 +1378,6 @@ static CURLcode add_parallel_transfers(CURLM *multi, CURLSH *share,
     if(result)
       return result;
 
-    errorbuf = malloc(CURL_ERROR_SIZE);
-    if(!errorbuf)
-      return CURLE_OUT_OF_MEMORY;
-
     /* parallel connect means that we do not set PIPEWAIT since pipewait
        will make libcurl prefer multiplexing */
     (void)curl_easy_setopt(per->curl, CURLOPT_PIPEWAIT,
@@ -1395,6 +1388,7 @@ static CURLcode add_parallel_transfers(CURLM *multi, CURLSH *share,
     (void)curl_easy_setopt(per->curl, CURLOPT_XFERINFOFUNCTION, xferinfo_cb);
     (void)curl_easy_setopt(per->curl, CURLOPT_XFERINFODATA, per);
     (void)curl_easy_setopt(per->curl, CURLOPT_NOPROGRESS, 0L);
+    (void)curl_easy_setopt(per->curl, CURLOPT_ERRORBUFFER, per->errorbuffer);
 #ifdef DEBUGBUILD
     if(getenv("CURL_FORBID_REUSE"))
       (void)curl_easy_setopt(per->curl, CURLOPT_FORBID_REUSE, 1L);
@@ -1415,13 +1409,10 @@ static CURLcode add_parallel_transfers(CURLM *multi, CURLSH *share,
           break;
       } while(skipped);
     }
-    if(result) {
-      free(errorbuf);
+    if(result)
       return result;
-    }
-    errorbuf[0] = 0;
-    (void)curl_easy_setopt(per->curl, CURLOPT_ERRORBUFFER, errorbuf);
-    per->errorbuffer = errorbuf;
+
+    per->errorbuffer[0] = 0;
     per->added = TRUE;
     all_added++;
     *addedp = TRUE;
@@ -1706,8 +1697,7 @@ static CURLcode check_finished(struct parastate *s)
       curl_easy_getinfo(easy, CURLINFO_PRIVATE, (void *)&ended);
       curl_multi_remove_handle(s->multi, easy);
 
-      if(ended->abort && (tres == CURLE_ABORTED_BY_CALLBACK) &&
-         ended->errorbuffer) {
+      if(ended->abort && (tres == CURLE_ABORTED_BY_CALLBACK)) {
         msnprintf(ended->errorbuffer, CURL_ERROR_SIZE,
                   "Transfer aborted due to critical error "
                   "in another transfer");
index a323271b76d2db857cd10298547641bb9a9fa760..19cb8b5248c20c3b10aab112f15a4d4c3bafaf15 100644 (file)
@@ -66,8 +66,7 @@ struct per_transfer {
 
   /* NULL or malloced */
   char *uploadfile;
-  char *errorbuffer; /* allocated and assigned while this is used for a
-                        transfer */
+  char errorbuffer[CURL_ERROR_SIZE];
   BIT(infdopen); /* TRUE if infd needs closing */
   BIT(noprogress);
   BIT(was_last_header_empty);
index 0a610de79ab1dcc6848bd046b4ce6a30c7e90d0b..225cf91fd4e6d961998b0752fb9a3f86566c58e4 100644 (file)
@@ -361,8 +361,8 @@ static int writeString(FILE *stream, const struct writeoutvar *wovar,
       break;
     case VAR_ERRORMSG:
       if(per_result) {
-        strinfo = (per->errorbuffer && per->errorbuffer[0]) ?
-          per->errorbuffer : curl_easy_strerror(per_result);
+        strinfo = (per->errorbuffer[0]) ? per->errorbuffer :
+          curl_easy_strerror(per_result);
         valid = true;
       }
       break;