]> granicus.if.org Git - curl/commitdiff
curl_multi_wait: avoid an unnecessary memory allocation
authorDaniel Stenberg <daniel@haxx.se>
Sun, 23 Dec 2012 20:06:40 +0000 (21:06 +0100)
committerYang Tse <yangsita@gmail.com>
Sun, 23 Dec 2012 20:50:14 +0000 (21:50 +0100)
lib/multi.c

index 2905a1346d89397920b2f6499b3f4f48be0d1066..b3a52d2fe9241fc146bde1a5a002f28a4fb6a7dc 100644 (file)
@@ -900,7 +900,7 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
   int bitmap;
   unsigned int i;
   unsigned int nfds = extra_nfds;
-  struct pollfd *ufds;
+  struct pollfd *ufds = NULL;
 
   if(!GOOD_MULTI_HANDLE(multi))
     return CURLM_BAD_HANDLE;
@@ -929,7 +929,8 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
     easy = easy->next; /* check next handle */
   }
 
-  ufds = (struct pollfd *)malloc(nfds * sizeof(struct pollfd));
+  if(nfds)
+    ufds = (struct pollfd *)malloc(nfds * sizeof(struct pollfd));
   nfds = 0;
 
   /* Add the curl handles to our pollfds first */
@@ -979,7 +980,7 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
   else
     i = 0;
 
-  free(ufds);
+  Curl_safefree(ufds);
   if(ret)
     *ret = i;
   return CURLM_OK;