From 18e84c88a02c6a525dc017d40337ab8bfa3d3b18 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 5 Jan 2021 11:42:26 +1100 Subject: [PATCH] [client] ll: fix failure to properly track the list size --- client/src/ll.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/src/ll.c b/client/src/ll.c index 15d109ec..944ccb41 100644 --- a/client/src/ll.c +++ b/client/src/ll.c @@ -41,9 +41,10 @@ struct ll struct ll * ll_new() { struct ll * list = malloc(sizeof(struct ll)); - list->head = NULL; - list->tail = NULL; - list->pos = NULL; + list->head = NULL; + list->tail = NULL; + list->pos = NULL; + list->count = 0; LG_LOCK_INIT(list->lock); return list; } @@ -64,6 +65,8 @@ void ll_push(struct ll * list, void * data) item->next = NULL; LG_LOCK(list->lock); + ++list->count; + if (!list->head) { list->head = item; @@ -72,7 +75,6 @@ void ll_push(struct ll * list, void * data) return; } - ++list->count; list->tail->next = item; list->tail = item; LG_UNLOCK(list->lock);