From 24110a58dc0e5c38751ffdfd698360f45b5e65d2 Mon Sep 17 00:00:00 2001 From: Arnaud Cornet Date: Sun, 28 Dec 2008 14:45:44 +0100 Subject: [PATCH] Fix leak + cleanup list_append. Thanks to TheMIROn for spotting the leak. --- src/irc.c | 6 ++++-- src/util.c | 19 ++++++++++--------- src/util.h | 4 +--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/irc.c b/src/irc.c index 6f31124..800bd87 100644 --- a/src/irc.c +++ b/src/irc.c @@ -672,9 +672,11 @@ static void irc_cli_backlog(struct link_client *ic) backlogl = log_backlogs(LINK(ic)->log); while ((bl = list_remove_first(backlogl))) { + list_t *bllines; + bllines = backlog_lines_from_last_mark(LINK(ic)->log, bl); mylog(LOG_INFO, "backlogging: %s", bl); - write_lines(CONN(ic), - backlog_lines_from_last_mark(LINK(ic)->log, bl)); + write_lines(CONN(ic), bllines); + list_free(bllines); free(bl); } list_free(backlogl); diff --git a/src/util.c b/src/util.c index 0a9f658..7a69b85 100644 --- a/src/util.c +++ b/src/util.c @@ -442,19 +442,20 @@ void list_free(list_t *t) free(t); } -void list_append(list_t *src, list_t *dest) +void list_append(list_t *dest, list_t *src) { - if (dest->last == NULL) + if (src->last == NULL) return; - if (src->first == NULL) { - src->first = dest->first; - src->last = dest->last; + if (dest->first == NULL) { + dest->first = src->first; + dest->last = src->last; + src->first = src->last = NULL; return; } - dest->first->prev = src->last; - src->last->next = dest->first; - src->last = dest->last; - free(dest); + src->first->prev = dest->last; + dest->last->next = src->first; + dest->last = src->last; + src->first = src->last = NULL; } /* diff --git a/src/util.h b/src/util.h index 3b841f6..389dbb4 100644 --- a/src/util.h +++ b/src/util.h @@ -112,9 +112,7 @@ void list_it_next(list_iterator_t *ti); void *list_it_item(list_iterator_t *ti); void *list_it_remove(list_iterator_t *li); void list_free(list_t *t); -void list_copy(list_t *src, list_t *dest); -/* dest must not be refed after wards */ -void list_append(list_t *src, list_t *dest); +void list_append(list_t *dest, list_t *src); int list_is_empty(list_t *l); void hash_init(hash_t *h, int);