]> granicus.if.org Git - curl/commitdiff
Curl_open: fix OOM return error correctly
authorDaniel Stenberg <daniel@haxx.se>
Mon, 20 Nov 2017 22:16:56 +0000 (23:16 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 21 Nov 2017 08:02:50 +0000 (09:02 +0100)
Closes #2098

lib/url.c

index d2208d5ebb65d87753d6d0f91574525acf902773..d0b9c7ef0ac803cdd2402d89a4fc5a1c67ce4d0f 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -569,32 +569,31 @@ CURLcode Curl_open(struct Curl_easy **curl)
     DEBUGF(fprintf(stderr, "Error: malloc of buffer failed\n"));
     result = CURLE_OUT_OF_MEMORY;
   }
-
-  Curl_mime_initpart(&data->set.mimepost, data);
-
-  data->state.headerbuff = malloc(HEADERSIZE);
-  if(!data->state.headerbuff) {
-    DEBUGF(fprintf(stderr, "Error: malloc of headerbuff failed\n"));
-    result = CURLE_OUT_OF_MEMORY;
-  }
   else {
-    result = Curl_init_userdefined(&data->set);
-
-    data->state.headersize = HEADERSIZE;
+    Curl_mime_initpart(&data->set.mimepost, data);
 
-    Curl_convert_init(data);
+    data->state.headerbuff = malloc(HEADERSIZE);
+    if(!data->state.headerbuff) {
+      DEBUGF(fprintf(stderr, "Error: malloc of headerbuff failed\n"));
+      result = CURLE_OUT_OF_MEMORY;
+    }
+    else {
+      result = Curl_init_userdefined(&data->set);
 
-    Curl_initinfo(data);
+      data->state.headersize = HEADERSIZE;
+      Curl_convert_init(data);
+      Curl_initinfo(data);
 
-    /* most recent connection is not yet defined */
-    data->state.lastconnect = NULL;
+      /* most recent connection is not yet defined */
+      data->state.lastconnect = NULL;
 
-    data->progress.flags |= PGRS_HIDE;
-    data->state.current_speed = -1; /* init to negative == impossible */
-    data->set.fnmatch = ZERO_NULL;
-    data->set.maxconnects = DEFAULT_CONNCACHE_SIZE; /* for easy handles */
+      data->progress.flags |= PGRS_HIDE;
+      data->state.current_speed = -1; /* init to negative == impossible */
+      data->set.fnmatch = ZERO_NULL;
+      data->set.maxconnects = DEFAULT_CONNCACHE_SIZE; /* for easy handles */
 
-    Curl_http2_init_state(&data->state);
+      Curl_http2_init_state(&data->state);
+    }
   }
 
   if(result) {