From 228fea46280d521dde6b214bb24fb20d9b6975f0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 10 May 2004 08:57:37 +0000 Subject: make Curl_llist_insert_next() fail properly if malloc() fails --- lib/llist.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib') 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; -- cgit v1.2.3