aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-08-09 23:20:21 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-08-09 23:20:21 +0200
commit9927956104340dd459daebec49181936518972fa (patch)
treeb230b2ca7bb8da80a8607836d67b98cbdd4100cf /src
parent71ff29ae8911db49a82cd61a97ced3d8530166c9 (diff)
downloadxK-9927956104340dd459daebec49181936518972fa.tar.gz
xK-9927956104340dd459daebec49181936518972fa.tar.xz
xK-9927956104340dd459daebec49181936518972fa.zip
kike: fix leaking of channels
Diffstat (limited to 'src')
-rw-r--r--src/kike.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/kike.c b/src/kike.c
index 18a906f..cc63195 100644
--- a/src/kike.c
+++ b/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 -----------------------------------------------------------------