hirc

IRC client
Log | Files | Refs

commit 1061e399a27ff0d40b88f73d304fa1d56985e2f0
parent 2c0741197de27a503bbd11b2f97bd8d53218611e
Author: hhvn <dev@hhvn.uk>
Date:   Thu, 24 Mar 2022 22:29:34 +0000

Free lists properly

Diffstat:
Msrc/chan.c | 8+++++---
Msrc/hist.c | 8+++++---
Msrc/nick.c | 8+++++---
3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/chan.c b/src/chan.c @@ -35,13 +35,15 @@ chan_free(struct Channel *channel) { void chan_free_list(struct Channel **head) { - struct Channel *p; + struct Channel *p, *prev; if (!head || !*head) return; - for (p = (*head)->next; p; p = p->next) - chan_free(p->prev); + for (prev = *head, p = prev->next; p; p = p->next) { + chan_free(prev); + prev = p; + } *head = NULL; } diff --git a/src/hist.c b/src/hist.c @@ -44,13 +44,15 @@ hist_free(struct History *history) { void hist_free_list(struct HistInfo *histinfo) { - struct History *p; + struct History *p, *prev; if (!histinfo->history) return; - for (p = histinfo->history->next; p; p = p->next) - hist_free(p->prev); + for (prev = histinfo->history, p = prev->next; p; p = p->next) { + hist_free(prev); + prev = p; + } histinfo->history = NULL; } diff --git a/src/nick.c b/src/nick.c @@ -112,13 +112,15 @@ nick_free(struct Nick *nick) { void nick_free_list(struct Nick **head) { - struct Nick *p; + struct Nick *p, *prev; if (!head || !*head) return; - for (p = (*head)->next; p; p = p->next) - nick_free(p->prev); + for (prev = *head, p = prev->next; p; p = p->next) { + nick_free(prev); + prev = p; + } *head = NULL; }