share_init: fix OOM crash

A failed calloc() would lead to NULL pointer use.

Coverity CID 1299427.
This commit is contained in:
Daniel Stenberg 2015-05-22 16:26:14 +02:00
parent 817323ed82
commit 03e2a9b023
1 changed files with 5 additions and 4 deletions

View File

@ -35,12 +35,13 @@ CURLSH *
curl_share_init(void) curl_share_init(void)
{ {
struct Curl_share *share = calloc(1, sizeof(struct Curl_share)); struct Curl_share *share = calloc(1, sizeof(struct Curl_share));
if(share) if(share) {
share->specifier |= (1<<CURL_LOCK_DATA_SHARE); share->specifier |= (1<<CURL_LOCK_DATA_SHARE);
if(Curl_mk_dnscache(&share->hostcache)) { if(Curl_mk_dnscache(&share->hostcache)) {
free(share); free(share);
return NULL; return NULL;
}
} }
return share; return share;