summaryrefslogtreecommitdiff
path: root/libs/libcurl/src/llist.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libcurl/src/llist.c')
-rw-r--r--libs/libcurl/src/llist.c69
1 files changed, 41 insertions, 28 deletions
diff --git a/libs/libcurl/src/llist.c b/libs/libcurl/src/llist.c
index 3d57779338..fa9fe1d556 100644
--- a/libs/libcurl/src/llist.c
+++ b/libs/libcurl/src/llist.c
@@ -32,12 +32,11 @@
/* this must be the last include file */
#include "memdebug.h"
+#ifdef DEBUGBUILD
#define LLISTINIT 0x100cc001 /* random pattern */
#define NODEINIT 0x12344321 /* random pattern */
#define NODEREM 0x54321012 /* random pattern */
-
-#ifdef DEBUGBUILD
#define VERIFYNODE(x) verifynode(x)
static struct Curl_llist_node *verifynode(struct Curl_llist_node *n)
{
@@ -86,7 +85,7 @@ Curl_llist_insert_next(struct Curl_llist *list,
#ifdef DEBUGBUILD
ne->_init = NODEINIT;
#endif
- ne->_ptr = (void *) p;
+ ne->_ptr = CURL_UNCONST(p);
ne->_list = list;
if(list->_size == 0) {
list->_head = ne;
@@ -134,40 +133,38 @@ Curl_llist_append(struct Curl_llist *list, const void *p,
Curl_llist_insert_next(list, list->_tail, p, ne);
}
-/*
- * @unittest: 1300
- */
-void
-Curl_node_uremove(struct Curl_llist_node *e, void *user)
+void *Curl_node_take_elem(struct Curl_llist_node *e)
{
void *ptr;
struct Curl_llist *list;
if(!e)
- return;
+ return NULL;
list = e->_list;
DEBUGASSERT(list);
DEBUGASSERT(list->_init == LLISTINIT);
DEBUGASSERT(list->_size);
DEBUGASSERT(e->_init == NODEINIT);
- if(e == list->_head) {
- list->_head = e->_next;
+ if(list) {
+ if(e == list->_head) {
+ list->_head = e->_next;
- if(!list->_head)
- list->_tail = NULL;
- else
- e->_next->_prev = NULL;
- }
- else {
- if(e->_prev)
- e->_prev->_next = e->_next;
+ if(!list->_head)
+ list->_tail = NULL;
+ else
+ e->_next->_prev = NULL;
+ }
+ else {
+ if(e->_prev)
+ e->_prev->_next = e->_next;
- if(!e->_next)
- list->_tail = e->_prev;
- else
- e->_next->_prev = e->_prev;
+ if(!e->_next)
+ list->_tail = e->_prev;
+ else
+ e->_next->_prev = e->_prev;
+ }
+ --list->_size;
}
-
ptr = e->_ptr;
e->_list = NULL;
@@ -178,11 +175,27 @@ Curl_node_uremove(struct Curl_llist_node *e, void *user)
e->_init = NODEREM; /* specific pattern on remove - not zero */
#endif
- --list->_size;
+ return ptr;
+}
+
+/*
+ * @unittest: 1300
+ */
+void
+Curl_node_uremove(struct Curl_llist_node *e, void *user)
+{
+ struct Curl_llist *list;
+ void *ptr;
+ if(!e)
+ return;
- /* call the dtor() last for when it actually frees the 'e' memory itself */
- if(list->_dtor)
- list->_dtor(user, ptr);
+ list = e->_list;
+ DEBUGASSERT(list);
+ if(list) {
+ ptr = Curl_node_take_elem(e);
+ if(list->_dtor)
+ list->_dtor(user, ptr);
+ }
}
void Curl_node_remove(struct Curl_llist_node *e)