projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
apache plugin: Fix a segmentation fault in the config handling of VerifyPeer / Verify...
[collectd.git]
/
src
/
utils_llist.c
diff --git
a/src/utils_llist.c
b/src/utils_llist.c
index
d5db9dc
..
bf5f7e4
100644
(file)
--- a/
src/utils_llist.c
+++ b/
src/utils_llist.c
@@
-35,6
+35,7
@@
struct llist_s
{
llentry_t *head;
llentry_t *tail;
{
llentry_t *head;
llentry_t *tail;
+ int size;
};
/*
};
/*
@@
-58,6
+59,9
@@
void llist_destroy (llist_t *l)
llentry_t *e_this;
llentry_t *e_next;
llentry_t *e_this;
llentry_t *e_next;
+ if (l == NULL)
+ return;
+
for (e_this = l->head; e_this != NULL; e_this = e_next)
{
e_next = e_this->next;
for (e_this = l->head; e_this != NULL; e_this = e_next)
{
e_next = e_this->next;
@@
-67,22
+71,16
@@
void llist_destroy (llist_t *l)
free (l);
}
free (l);
}
-llentry_t *llentry_create (c
onst c
har *key, void *value)
+llentry_t *llentry_create (char *key, void *value)
{
llentry_t *e;
e = (llentry_t *) malloc (sizeof (llentry_t));
{
llentry_t *e;
e = (llentry_t *) malloc (sizeof (llentry_t));
- if (e == NULL)
- return (NULL);
-
- e->key = strdup (key);
- e->value = value;
- e->next = NULL;
-
- if (e->key == NULL)
+ if (e)
{
{
- free (e);
- return (NULL);
+ e->key = key;
+ e->value = value;
+ e->next = NULL;
}
return (e);
}
return (e);
@@
-90,7
+88,6
@@
llentry_t *llentry_create (const char *key, void *value)
void llentry_destroy (llentry_t *e)
{
void llentry_destroy (llentry_t *e)
{
- free (e->key);
free (e);
}
free (e);
}
@@
-104,6
+101,8
@@
void llist_append (llist_t *l, llentry_t *e)
l->tail->next = e;
l->tail = e;
l->tail->next = e;
l->tail = e;
+
+ ++(l->size);
}
void llist_prepend (llist_t *l, llentry_t *e)
}
void llist_prepend (llist_t *l, llentry_t *e)
@@
-113,6
+112,8
@@
void llist_prepend (llist_t *l, llentry_t *e)
if (l->tail == NULL)
l->tail = e;
if (l->tail == NULL)
l->tail = e;
+
+ ++(l->size);
}
void llist_remove (llist_t *l, llentry_t *e)
}
void llist_remove (llist_t *l, llentry_t *e)
@@
-129,12
+130,22
@@
void llist_remove (llist_t *l, llentry_t *e)
l->head = e->next;
if (l->tail == e)
l->tail = prev;
l->head = e->next;
if (l->tail == e)
l->tail = prev;
+
+ --(l->size);
+}
+
+int llist_size (llist_t *l)
+{
+ return (l ? l->size : 0);
}
llentry_t *llist_search (llist_t *l, const char *key)
{
llentry_t *e;
}
llentry_t *llist_search (llist_t *l, const char *key)
{
llentry_t *e;
+ if (l == NULL)
+ return (NULL);
+
for (e = l->head; e != NULL; e = e->next)
if (strcmp (key, e->key) == 0)
break;
for (e = l->head; e != NULL; e = e->next)
if (strcmp (key, e->key) == 0)
break;
@@
-144,10
+155,14
@@
llentry_t *llist_search (llist_t *l, const char *key)
llentry_t *llist_head (llist_t *l)
{
llentry_t *llist_head (llist_t *l)
{
+ if (l == NULL)
+ return (NULL);
return (l->head);
}
llentry_t *llist_tail (llist_t *l)
{
return (l->head);
}
llentry_t *llist_tail (llist_t *l)
{
+ if (l == NULL)
+ return (NULL);
return (l->tail);
}
return (l->tail);
}