diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-05-10 08:57:18 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-05-10 08:57:18 +0000 |
commit | e64dacb40e3a32682a2481bedf83fd5f91cdde71 (patch) | |
tree | a665099c467264f9a7e996b614d991406dae7104 /lib/hash.c | |
parent | fff01f24bf8dabf7bb6edb7ebdc7cba197d6039b (diff) | |
download | curl-e64dacb40e3a32682a2481bedf83fd5f91cdde71.tar.gz |
better checking that strdup() works
Diffstat (limited to 'lib/hash.c')
-rw-r--r-- | lib/hash.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/hash.c b/lib/hash.c index 619f2fb1b..fcc13ed28 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -127,9 +127,17 @@ 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); - he->key_len = key_len; - he->ptr = (void *) p; + 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; } |