mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
better checking that strdup() works
This commit is contained in:
parent
fff01f24bf
commit
e64dacb40e
10
lib/hash.c
10
lib/hash.c
@ -127,10 +127,18 @@ mk_hash_element(char *key, size_t key_len, const void *p)
|
||||
(curl_hash_element *) malloc(sizeof(curl_hash_element));
|
||||
|
||||
if(he) {
|
||||
he->key = strdup(key);
|
||||
char *dup = strdup(key);
|
||||
if(dup) {
|
||||
he->key = dup;
|
||||
he->key_len = key_len;
|
||||
he->ptr = (void *) p;
|
||||
}
|
||||
else {
|
||||
/* failed to duplicate the key, free memory and fail */
|
||||
free(he);
|
||||
he = NULL;
|
||||
}
|
||||
}
|
||||
return he;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user