monitor: fix the resource leak properly, unlike the moronic elemental-ircd developers
This commit is contained in:
parent
dd64bf8dad
commit
d5f856c68e
2 changed files with 15 additions and 7 deletions
|
@ -17,10 +17,10 @@ struct monitor
|
||||||
struct monitor *hnext;
|
struct monitor *hnext;
|
||||||
char name[NICKLEN];
|
char name[NICKLEN];
|
||||||
rb_dlink_list users;
|
rb_dlink_list users;
|
||||||
|
rb_dlink_node node;
|
||||||
|
unsigned int hashv;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct monitor *monitorTable[];
|
|
||||||
|
|
||||||
#define MONITOR_HASH_BITS 16
|
#define MONITOR_HASH_BITS 16
|
||||||
#define MONITOR_HASH_SIZE (1<<MONITOR_HASH_BITS)
|
#define MONITOR_HASH_SIZE (1<<MONITOR_HASH_BITS)
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "numeric.h"
|
#include "numeric.h"
|
||||||
#include "send.h"
|
#include "send.h"
|
||||||
|
|
||||||
struct monitor *monitorTable[MONITOR_HASH_SIZE];
|
static rb_dlink_list monitorTable[MONITOR_HASH_SIZE];
|
||||||
static rb_bh *monitor_heap;
|
static rb_bh *monitor_heap;
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -57,23 +57,25 @@ struct monitor *
|
||||||
find_monitor(const char *name, int add)
|
find_monitor(const char *name, int add)
|
||||||
{
|
{
|
||||||
struct monitor *monptr;
|
struct monitor *monptr;
|
||||||
|
rb_dlink_node *ptr;
|
||||||
|
|
||||||
unsigned int hashv = hash_monitor_nick(name);
|
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))
|
if(!irccmp(monptr->name, name))
|
||||||
return monptr;
|
return monptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(add)
|
if(add)
|
||||||
{
|
{
|
||||||
monptr = rb_bh_alloc(monitor_heap);
|
monptr = rb_bh_alloc(monitor_heap);
|
||||||
rb_strlcpy(monptr->name, name, sizeof(monptr->name));
|
rb_strlcpy(monptr->name, name, sizeof(monptr->name));
|
||||||
|
monptr->hashv = hashv;
|
||||||
|
|
||||||
monptr->hnext = monitorTable[hashv];
|
rb_dlinkAdd(monptr, &monptr->node, &monitorTable[hashv]);
|
||||||
monitorTable[hashv] = monptr;
|
|
||||||
|
|
||||||
return monptr;
|
return monptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +85,10 @@ find_monitor(const char *name, int add)
|
||||||
void
|
void
|
||||||
free_monitor(struct monitor *monptr)
|
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);
|
rb_bh_free(monitor_heap, monptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +146,8 @@ clear_monitor(struct Client *client_p)
|
||||||
|
|
||||||
rb_dlinkFindDestroy(client_p, &monptr->users);
|
rb_dlinkFindDestroy(client_p, &monptr->users);
|
||||||
rb_free_rb_dlink_node(ptr);
|
rb_free_rb_dlink_node(ptr);
|
||||||
|
|
||||||
|
free_monitor(ptr->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
client_p->localClient->monitor_list.head = client_p->localClient->monitor_list.tail = NULL;
|
client_p->localClient->monitor_list.head = client_p->localClient->monitor_list.tail = NULL;
|
||||||
|
|
Loading…
Reference in a new issue