diff options
Diffstat (limited to 'zyklonb.c')
| -rw-r--r-- | zyklonb.c | 27 | 
1 files changed, 11 insertions, 16 deletions
| @@ -83,11 +83,10 @@ struct plugin  	struct str write_buffer;            ///< Output yet to be sent out  }; -static void -plugin_init (struct plugin *self) +static struct plugin * +plugin_new (void)  { -	memset (self, 0, sizeof *self); - +	struct plugin *self = xcalloc (1, sizeof *self);  	self->pid = -1;  	self->queued_output = str_make (); @@ -95,10 +94,11 @@ plugin_init (struct plugin *self)  	self->read_buffer = str_make ();  	self->write_fd = -1;  	self->write_buffer = str_make (); +	return self;  }  static void -plugin_free (struct plugin *self) +plugin_destroy (struct plugin *self)  {  	soft_assert (self->pid == -1);  	free (self->name); @@ -113,6 +113,8 @@ plugin_free (struct plugin *self)  	if (!self->initialized)  		str_free (&self->queued_output); + +	free (self);  }  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -192,13 +194,8 @@ bot_context_free (struct bot_context *self)  	str_free (&self->read_buffer);  	// TODO: terminate the plugins properly before this is called -	struct plugin *link, *tmp; -	for (link = self->plugins; link; link = tmp) -	{ -		tmp = link->next; -		plugin_free (link); -		free (link); -	} +	LIST_FOR_EACH (struct plugin, link, self->plugins) +		plugin_destroy (link);  	if (self->irc_fd != -1)  	{ @@ -1099,8 +1096,7 @@ plugin_launch (struct bot_context *ctx, const char *name, struct error **e)  	xclose (stdin_pipe[0]);  	xclose (stdout_pipe[1]); -	struct plugin *plugin = xmalloc (sizeof *plugin); -	plugin_init (plugin); +	struct plugin *plugin = plugin_new ();  	plugin->ctx = ctx;  	plugin->pid = pid;  	plugin->name = xstrdup (name); @@ -1876,8 +1872,7 @@ on_plugin_death (struct plugin *plugin, int status)  	plugin->read_fd = -1;  	LIST_UNLINK (ctx->plugins, plugin); -	plugin_free (plugin); -	free (plugin); +	plugin_destroy (plugin);  	// Living child processes block us from quitting  	try_finish_quit (ctx); | 
