diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-05-10 08:57:37 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-05-10 08:57:37 +0000 |
commit | 228fea46280d521dde6b214bb24fb20d9b6975f0 (patch) | |
tree | 302b4699cd79312c6a0e0bc75a02bbd4b5e80c49 /lib | |
parent | e64dacb40e3a32682a2481bedf83fd5f91cdde71 (diff) |
make Curl_llist_insert_next() fail properly if malloc() fails
Diffstat (limited to 'lib')
-rw-r--r-- | lib/llist.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/llist.c b/lib/llist.c index 087cf8545..0f347acb9 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -55,24 +55,31 @@ Curl_llist_alloc(curl_llist_dtor dtor) return list; } +/* + * Curl_llist_insert_next() returns 1 on success and 0 on failure. + */ int Curl_llist_insert_next(curl_llist *list, curl_llist_element *e, const void *p) { - curl_llist_element *ne; + curl_llist_element *ne = + (curl_llist_element *) malloc(sizeof(curl_llist_element)); + if(!ne) + return 0; - ne = (curl_llist_element *) malloc(sizeof(curl_llist_element)); ne->ptr = (void *) p; if (list->size == 0) { list->head = ne; list->head->prev = NULL; list->head->next = NULL; list->tail = ne; - } else { + } + else { ne->next = e->next; ne->prev = e; if (e->next) { e->next->prev = ne; - } else { + } + else { list->tail = ne; } e->next = ne; |