diff options
Diffstat (limited to 'src/rspamadm/rspamadm.c')
-rw-r--r-- | src/rspamadm/rspamadm.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index 565601956..6108a179b 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -352,6 +352,21 @@ rspamadm_add_lua_globals (struct rspamd_dns_resolver *resolver) lua_setglobal (L, "rspamadm_dns_resolver"); } +static void +rspamadm_cmd_dtor (gpointer p) +{ + struct rspamadm_command *cmd = (struct rspamadm_command *)p; + + if (cmd->flags & RSPAMADM_FLAG_DYNAMIC) { + if (cmd->aliases) { + g_ptr_array_free (cmd->aliases, TRUE); + } + + g_free ((gpointer)cmd->name); + g_free (cmd); + } +} + gint main (gint argc, gchar **argv, gchar **env) { @@ -364,10 +379,12 @@ main (gint argc, gchar **argv, gchar **env) const gchar *cmd_name; const struct rspamadm_command *cmd; struct rspamd_dns_resolver *resolver; - GPtrArray *all_commands = g_ptr_array_new (); /* Discovered during check */ + GPtrArray *all_commands = g_ptr_array_new_full (32, + rspamadm_cmd_dtor); /* Discovered during check */ gint i, nargc, targc; worker_t **pworker; gboolean lua_file = FALSE; + gint retcode = 0; ucl_vars = g_hash_table_new_full (rspamd_strcase_hash, rspamd_strcase_equal, g_free, g_free); @@ -417,9 +434,12 @@ main (gint argc, gchar **argv, gchar **env) if (!g_option_context_parse (context, &targc, &targv, &error)) { fprintf (stderr, "option parsing failed: %s\n", error->message); g_error_free (error); + g_option_context_free (context); exit (1); } + g_option_context_free (context); + /* Setup logger */ if (verbose) { cfg->log_level = G_LOG_LEVEL_DEBUG; @@ -469,7 +489,7 @@ main (gint argc, gchar **argv, gchar **env) rspamd_fprintf (stderr, "Cannot load lua environment: %e", error); g_error_free (error); - exit (EXIT_FAILURE); + goto end; } rspamd_lua_set_globals (cfg, L); @@ -500,15 +520,15 @@ main (gint argc, gchar **argv, gchar **env) if (show_version) { rspamadm_version (); - exit (EXIT_SUCCESS); + goto end; } if (show_help) { rspamadm_usage (context); - exit (EXIT_SUCCESS); + goto end; } if (list_commands) { rspamadm_commands (all_commands); - exit (EXIT_SUCCESS); + goto end; } cmd_name = argv[nargc]; @@ -547,7 +567,8 @@ main (gint argc, gchar **argv, gchar **env) } } - exit (EXIT_FAILURE); + retcode = EXIT_FAILURE; + goto end; } if (nargc < argc) { @@ -592,12 +613,14 @@ main (gint argc, gchar **argv, gchar **env) ev_break (rspamd_main->event_loop, EVBREAK_ALL); - +end: + rspamd_dns_resolver_deinit (resolver); REF_RELEASE (rspamd_main->cfg); rspamd_log_close (rspamd_main->logger, TRUE); + rspamd_url_deinit (); g_free (rspamd_main); g_ptr_array_free (all_commands, TRUE); - return 0; + return retcode; } |