make Curl_llist_insert_next() fail properly if malloc() fails
This commit is contained in:
parent
e64dacb40e
commit
228fea4628
15
lib/llist.c
15
lib/llist.c
@ -55,24 +55,31 @@ Curl_llist_alloc(curl_llist_dtor dtor)
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Curl_llist_insert_next() returns 1 on success and 0 on failure.
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
Curl_llist_insert_next(curl_llist *list, curl_llist_element *e, const void *p)
|
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;
|
ne->ptr = (void *) p;
|
||||||
if (list->size == 0) {
|
if (list->size == 0) {
|
||||||
list->head = ne;
|
list->head = ne;
|
||||||
list->head->prev = NULL;
|
list->head->prev = NULL;
|
||||||
list->head->next = NULL;
|
list->head->next = NULL;
|
||||||
list->tail = ne;
|
list->tail = ne;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
ne->next = e->next;
|
ne->next = e->next;
|
||||||
ne->prev = e;
|
ne->prev = e;
|
||||||
if (e->next) {
|
if (e->next) {
|
||||||
e->next->prev = ne;
|
e->next->prev = ne;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
list->tail = ne;
|
list->tail = ne;
|
||||||
}
|
}
|
||||||
e->next = ne;
|
e->next = ne;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user