0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-05 15:18:52 +02:00

monitor: fix the resource leak properly, unlike the moronic elemental-ircd developers

This commit is contained in:
William Pitcock 2015-10-11 18:48:53 -05:00
parent dd64bf8dad
commit d5f856c68e
2 changed files with 15 additions and 7 deletions

View file

@ -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<<MONITOR_HASH_BITS)

View file

@ -38,7 +38,7 @@
#include "numeric.h"
#include "send.h"
struct monitor *monitorTable[MONITOR_HASH_SIZE];
static rb_dlink_list monitorTable[MONITOR_HASH_SIZE];
static rb_bh *monitor_heap;
void
@ -57,23 +57,25 @@ struct monitor *
find_monitor(const char *name, int add)
{
struct monitor *monptr;
rb_dlink_node *ptr;
unsigned int hashv = hash_monitor_nick(name);
for(monptr = monitorTable[hashv]; monptr; monptr = monptr->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;