From: Daniel Stenberg Date: Sun, 23 Dec 2012 20:06:40 +0000 (+0100) Subject: curl_multi_wait: avoid an unnecessary memory allocation X-Git-Tag: curl-7_29_0~195 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a1fc9b80c842e74243b6a0e52f2c64e4a96210ce;p=curl curl_multi_wait: avoid an unnecessary memory allocation --- diff --git a/lib/multi.c b/lib/multi.c index 2905a1346..b3a52d2fe 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -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;