projects
/
platform
/
upstream
/
curl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
fff01f2
)
better checking that strdup() works
author
Daniel Stenberg
<daniel@haxx.se>
Mon, 10 May 2004 08:57:18 +0000
(08:57 +0000)
committer
Daniel Stenberg
<daniel@haxx.se>
Mon, 10 May 2004 08:57:18 +0000
(08:57 +0000)
lib/hash.c
patch
|
blob
|
history
diff --git
a/lib/hash.c
b/lib/hash.c
index
619f2fb
..
fcc13ed
100644
(file)
--- 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;
}