From d5f856c68ea790b4369db28f0429c2be2c22aab0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 11 Oct 2015 18:48:53 -0500 Subject: [PATCH] monitor: fix the resource leak properly, unlike the moronic elemental-ircd developers --- include/monitor.h | 4 ++-- src/monitor.c | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/monitor.h b/include/monitor.h index bff6ae922..633d569a4 100644 --- a/include/monitor.h +++ b/include/monitor.h @@ -17,10 +17,10 @@ struct monitor struct monitor *hnext; char name[NICKLEN]; rb_dlink_list users; + rb_dlink_node node; + unsigned int hashv; }; -extern struct monitor *monitorTable[]; - #define MONITOR_HASH_BITS 16 #define MONITOR_HASH_SIZE (1<hnext) + RB_DLINK_FOREACH(ptr, monitorTable[hashv].head) { + monptr = ptr->data; if(!irccmp(monptr->name, name)) return monptr; + } if(add) { monptr = rb_bh_alloc(monitor_heap); rb_strlcpy(monptr->name, name, sizeof(monptr->name)); + monptr->hashv = hashv; - monptr->hnext = monitorTable[hashv]; - monitorTable[hashv] = monptr; - + rb_dlinkAdd(monptr, &monptr->node, &monitorTable[hashv]); return monptr; } @@ -83,6 +85,10 @@ find_monitor(const char *name, int add) void free_monitor(struct monitor *monptr) { + if (rb_dlink_list_length(&monptr->users) > 0) + return; + + rb_dlinkDelete(&monptr->node, &monitorTable[monptr->hashv]); rb_bh_free(monitor_heap, monptr); } @@ -140,6 +146,8 @@ clear_monitor(struct Client *client_p) rb_dlinkFindDestroy(client_p, &monptr->users); rb_free_rb_dlink_node(ptr); + + free_monitor(ptr->data); } client_p->localClient->monitor_list.head = client_p->localClient->monitor_list.tail = NULL;