kike: fix leaking of channels
This commit is contained in:
parent
71ff29ae89
commit
9927956104
23
src/kike.c
23
src/kike.c
|
@ -370,10 +370,10 @@ struct channel
|
|||
struct str_vector invite_list; ///< Exceptions from +I
|
||||
};
|
||||
|
||||
static void
|
||||
channel_init (struct channel *self)
|
||||
static struct channel *
|
||||
channel_new (void)
|
||||
{
|
||||
memset (self, 0, sizeof *self);
|
||||
struct channel *self = xcalloc (1, sizeof *self);
|
||||
|
||||
self->user_limit = -1;
|
||||
self->topic = xstrdup ("");
|
||||
|
@ -381,10 +381,11 @@ channel_init (struct channel *self)
|
|||
str_vector_init (&self->ban_list);
|
||||
str_vector_init (&self->exception_list);
|
||||
str_vector_init (&self->invite_list);
|
||||
return self;
|
||||
}
|
||||
|
||||
static void
|
||||
channel_free (struct channel *self)
|
||||
channel_delete (struct channel *self)
|
||||
{
|
||||
free (self->name);
|
||||
free (self->key);
|
||||
|
@ -400,6 +401,8 @@ channel_free (struct channel *self)
|
|||
str_vector_free (&self->ban_list);
|
||||
str_vector_free (&self->exception_list);
|
||||
str_vector_free (&self->invite_list);
|
||||
|
||||
free (self);
|
||||
}
|
||||
|
||||
static char *
|
||||
|
@ -466,9 +469,9 @@ server_context_init (struct server_context *self)
|
|||
|
||||
str_map_init (&self->users);
|
||||
self->users.key_xfrm = irc_strxfrm;
|
||||
// TODO: set channel_free() as the free function?
|
||||
str_map_init (&self->channels);
|
||||
self->channels.key_xfrm = irc_strxfrm;
|
||||
self->channels.free = (void (*) (void *)) channel_delete;
|
||||
str_map_init (&self->handlers);
|
||||
self->handlers.key_xfrm = irc_strxfrm;
|
||||
|
||||
|
@ -587,12 +590,10 @@ channel_user_count (const struct channel *chan)
|
|||
static struct channel *
|
||||
channel_create (struct server_context *ctx, const char *name)
|
||||
{
|
||||
struct channel *chan = xcalloc (1, sizeof *chan);
|
||||
channel_init (chan);
|
||||
str_map_set (&ctx->channels, name, chan);
|
||||
|
||||
struct channel *chan = channel_new ();
|
||||
chan->ctx = ctx;
|
||||
chan->name = xstrdup (name);
|
||||
str_map_set (&ctx->channels, name, chan);
|
||||
return chan;
|
||||
}
|
||||
|
||||
|
@ -600,11 +601,7 @@ static void
|
|||
channel_destroy_if_empty (struct server_context *ctx, struct channel *chan)
|
||||
{
|
||||
if (!chan->users)
|
||||
{
|
||||
str_map_set (&ctx->channels, chan->name, NULL);
|
||||
channel_free (chan);
|
||||
free (chan);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Clients -----------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue