commit 1a072907420181c28c824fe42699d3d7c44b426c
parent 1b3bba71f5a04b17a238ed1a31569e8b12ecf5ee
Author: hhvn <dev@hhvn.uk>
Date: Thu, 21 Apr 2022 16:08:00 +0100
Memory leak-free according to valgrind
Diffstat:
5 files changed, 33 insertions(+), 14 deletions(-)
diff --git a/src/chan.c b/src/chan.c
@@ -40,9 +40,13 @@ chan_free_list(struct Channel **head) {
if (!head || !*head)
return;
- for (prev = *head, p = prev->next; p; p = p->next) {
+ prev = *head;
+ p = prev->next;
+ while (prev) {
chan_free(prev);
prev = p;
+ if (p)
+ p = p->next;
}
*head = NULL;
}
diff --git a/src/handle.c b/src/handle.c
@@ -693,7 +693,7 @@ handle(struct Server *server, char *msg) {
hist_free(hist);
}
/* NULL handlers will stop a message being added to server->history */
- return;
+ goto end;
}
}
@@ -702,5 +702,7 @@ handle(struct Server *server, char *msg) {
hist_add(server->history, msg, Activity_error, timestamp, HIST_DFL|HIST_SERR);
else
hist_add(server->history, msg, Activity_status, timestamp, HIST_DFL);
+
+end:
param_free(params);
}
diff --git a/src/hist.c b/src/hist.c
@@ -33,10 +33,7 @@
void
hist_free(struct History *history) {
param_free(history->_params);
- if (history->from) {
- pfree(&history->from->prefix);
- pfree(&history->from);
- }
+ nick_free(history->from);
pfree(&history->raw);
pfree(&history->format);
pfree(&history->rformat);
@@ -50,9 +47,13 @@ hist_free_list(struct HistInfo *histinfo) {
if (!histinfo->history)
return;
- for (prev = histinfo->history, p = prev->next; p; p = p->next) {
+ prev = histinfo->history;
+ p = prev->next;
+ while (prev) {
hist_free(prev);
prev = p;
+ if (p)
+ p = p->next;
}
histinfo->history = NULL;
}
@@ -383,8 +384,10 @@ hist_loadlog(struct HistInfo *hist, char *server, char *channel) {
if (!tok[0] || !tok[1] || !tok[2] ||
!tok[3] || !tok[4] || !tok[5] ||
- !tok[6] || !tok[7] || !msg)
+ !tok[6] || !tok[7] || !msg) {
+ pfree(&lines[i]);
continue;
+ }
timestamp = (time_t)strtoll(tok[0], NULL, 10);
activity = (int)strtol(tok[1], NULL, 10);
@@ -418,6 +421,7 @@ hist_loadlog(struct HistInfo *hist, char *server, char *channel) {
prev = p;
nick_free(from);
+ pfree(&prefix);
pfree(&lines[i]);
}
diff --git a/src/nick.c b/src/nick.c
@@ -117,9 +117,13 @@ nick_free_list(struct Nick **head) {
if (!head || !*head)
return;
- for (prev = *head, p = prev->next; p; p = p->next) {
+ prev = *head;
+ p = prev->next;
+ while (prev) {
nick_free(prev);
prev = p;
+ if (p)
+ p = p->next;
}
*head = NULL;
}
diff --git a/src/serv.c b/src/serv.c
@@ -33,7 +33,7 @@
void
serv_free(struct Server *server) {
- struct Support *p;
+ struct Support *p, *prev;
if (!server)
return;
@@ -48,10 +48,15 @@ serv_free(struct Server *server) {
hist_free_list(server->history);
chan_free_list(&server->channels);
chan_free_list(&server->privs);
- for (p = server->supports; p; p = p->next) {
- pfree(&p->prev);
- pfree(&p->key);
- pfree(&p->value);
+ prev = server->supports;
+ p = prev->next;
+ while (prev) {
+ pfree(&prev->key);
+ pfree(&prev->value);
+ pfree(&prev);
+ prev = p;
+ if (p)
+ p = p->next;
}
#ifdef TLS
if (server->tls)