mirror of
https://github.com/curl/curl.git
synced 2025-09-17 17:42:49 +03: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));
|
(curl_hash_element *) malloc(sizeof(curl_hash_element));
|
||||||
|
|
||||||
if(he) {
|
if(he) {
|
||||||
he->key = strdup(key);
|
char *dup = strdup(key);
|
||||||
|
if(dup) {
|
||||||
|
he->key = dup;
|
||||||
he->key_len = key_len;
|
he->key_len = key_len;
|
||||||
he->ptr = (void *) p;
|
he->ptr = (void *) p;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
/* failed to duplicate the key, free memory and fail */
|
||||||
|
free(he);
|
||||||
|
he = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
return he;
|
return he;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user