Skip to content

Commit

Permalink
[Minor] Further static leaks removal
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Sep 27, 2019
1 parent 0cde7b0 commit 3da3ad2
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/controller.c
Expand Up @@ -3769,6 +3769,9 @@ start_controller_worker (struct rspamd_worker *worker)
/* Accept event */
ctx->http_ctx = rspamd_http_context_create (ctx->cfg, ctx->event_loop,
ctx->cfg->ups_ctx);
rspamd_mempool_add_destructor (ctx->cfg->cfg_pool,
(rspamd_mempool_destruct_t)rspamd_http_context_free,
ctx->http_ctx);
ctx->http = rspamd_http_router_new (rspamd_controller_error_handler,
rspamd_controller_finish_handler, ctx->timeout,
ctx->static_files_dir, ctx->http_ctx);
Expand Down Expand Up @@ -3942,9 +3945,7 @@ start_controller_worker (struct rspamd_worker *worker)
g_hash_table_unref (ctx->plugins);
g_hash_table_unref (ctx->custom_commands);

struct rspamd_http_context *http_ctx = ctx->http_ctx;
REF_RELEASE (ctx->cfg);
rspamd_http_context_free (http_ctx);
rspamd_log_close (worker->srv->logger, TRUE);

exit (EXIT_SUCCESS);
Expand Down
9 changes: 9 additions & 0 deletions src/libcryptobox/cryptobox.c
Expand Up @@ -310,6 +310,15 @@ rspamd_cryptobox_init (void)
return ctx;
}

void
rspamd_cryptobox_deinit (struct rspamd_cryptobox_library_ctx *ctx)
{
if (ctx) {
g_free (ctx->cpu_extensions);
g_free (ctx);
}
}

void
rspamd_cryptobox_keypair (rspamd_pk_t pk, rspamd_sk_t sk,
enum rspamd_cryptobox_mode mode)
Expand Down
1 change: 1 addition & 0 deletions src/libcryptobox/cryptobox.h
Expand Up @@ -84,6 +84,7 @@ struct rspamd_cryptobox_library_ctx {
*/
struct rspamd_cryptobox_library_ctx *rspamd_cryptobox_init (void);

void rspamd_cryptobox_deinit (struct rspamd_cryptobox_library_ctx *);
/**
* Generate new keypair
* @param pk public key buffer
Expand Down
10 changes: 6 additions & 4 deletions src/libserver/cfg_utils.c
Expand Up @@ -124,10 +124,12 @@ struct rspamd_config *
rspamd_config_new (enum rspamd_config_init_flags flags)
{
struct rspamd_config *cfg;
rspamd_mempool_t *pool;

cfg = g_malloc0 (sizeof (*cfg));
pool = rspamd_mempool_new (8 * 1024 * 1024, "cfg");
cfg = rspamd_mempool_alloc0 (pool, sizeof (*cfg));
/* Allocate larger pool for cfg */
cfg->cfg_pool = rspamd_mempool_new (8 * 1024 * 1024, "cfg");
cfg->cfg_pool = pool;
cfg->dns_timeout = 1.0;
cfg->dns_retransmits = 5;
/* 16 sockets per DNS server */
Expand Down Expand Up @@ -311,7 +313,7 @@ rspamd_config_free (struct rspamd_config *cfg)

HASH_CLEAR (hh, cfg->actions);

rspamd_mempool_delete (cfg->cfg_pool);
rspamd_mempool_destructors_enforce (cfg->cfg_pool);

if (cfg->checksum) {
g_free (cfg->checksum);
Expand All @@ -324,7 +326,7 @@ rspamd_config_free (struct rspamd_config *cfg)
g_free (lp);
}

g_free (cfg);
rspamd_mempool_delete (cfg->cfg_pool);
}

const ucl_object_t *
Expand Down
5 changes: 1 addition & 4 deletions src/libutil/http_context.c
Expand Up @@ -54,8 +54,7 @@ rspamd_http_keepalive_queue_cleanup (GQueue *conns)

cbd = (struct rspamd_http_keepalive_cbdata *)cur->data;
rspamd_http_connection_unref (cbd->conn);
/* Event is deleted here by deletion of the ev_base */
/* event_del (&cbd->ev); */
rspamd_ev_watcher_stop (cbd->ctx->event_loop, &cbd->ev);
g_free (cbd);

cur = cur->next;
Expand Down Expand Up @@ -173,8 +172,6 @@ rspamd_http_context_parse_proxy (struct rspamd_http_context *ctx,
static void
rspamd_http_context_init (struct rspamd_http_context *ctx)
{


if (ctx->config.kp_cache_size_client > 0) {
ctx->client_kp_cache = rspamd_keypair_cache_new (ctx->config.kp_cache_size_client);
}
Expand Down
20 changes: 17 additions & 3 deletions src/libutil/logger.c
Expand Up @@ -357,9 +357,10 @@ rspamd_log_close_priv (rspamd_logger_t *rspamd_log, gboolean termination, uid_t
rspamd_log->opened = FALSE;
}

if (termination && rspamd_log->log_file) {
if (termination) {
g_free (rspamd_log->log_file);
rspamd_log->log_file = NULL;
g_free (rspamd_log);
}
}

Expand Down Expand Up @@ -1445,6 +1446,15 @@ rspamd_logger_allocate_mod_bit (void)
}
}

RSPAMD_DESTRUCTOR (rspamd_debug_modules_dtor)
{
if (log_modules) {
g_hash_table_unref (log_modules->modules);
g_free (log_modules->bitset);
g_free (log_modules);
}
}

guint
rspamd_logger_add_debug_module (const gchar *mname)
{
Expand All @@ -1455,9 +1465,13 @@ rspamd_logger_add_debug_module (const gchar *mname)
}

if (log_modules == NULL) {
/*
* This is usually called from constructors, so we call init check
* each time to avoid dependency issues between ctors calls
*/
log_modules = g_malloc0 (sizeof (*log_modules));
log_modules->modules = g_hash_table_new (rspamd_strcase_hash,
rspamd_strcase_equal);
log_modules->modules = g_hash_table_new_full (rspamd_strcase_hash,
rspamd_strcase_equal, g_free, g_free);
log_modules->bitset_allocated = 16;
log_modules->bitset_len = 0;
log_modules->bitset = g_malloc0 (log_modules->bitset_allocated);
Expand Down
1 change: 1 addition & 0 deletions src/libutil/regexp.c
Expand Up @@ -1055,6 +1055,7 @@ rspamd_regexp_cache_destroy (struct rspamd_regexp_cache *cache)
}
#endif
#endif
g_free (cache);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libutil/util.c
Expand Up @@ -2573,6 +2573,8 @@ rspamd_deinit_libs (struct rspamd_external_libs_ctx *ctx)
ZSTD_freeDStream (ctx->in_zstream);
}

rspamd_cryptobox_deinit (ctx->crypto_ctx);

g_free (ctx);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/rspamadm/configtest.c
Expand Up @@ -128,12 +128,16 @@ rspamadm_configtest (gint argc, gchar **argv, const struct rspamadm_command *cmd
g_option_context_free (context);

if (config == NULL) {
static gchar fbuf[PATH_MAX];

if ((confdir = g_hash_table_lookup (ucl_vars, "CONFDIR")) == NULL) {
confdir = RSPAMD_CONFDIR;
}

config = g_strdup_printf ("%s%c%s", confdir, G_DIR_SEPARATOR,
rspamd_snprintf (fbuf, sizeof (fbuf), "%s%c%s",
confdir, G_DIR_SEPARATOR,
"rspamd.conf");
config = fbuf;
}

pworker = &workers[0];
Expand Down
5 changes: 4 additions & 1 deletion src/rspamadm/rspamadm.c
Expand Up @@ -619,8 +619,11 @@ main (gint argc, gchar **argv, gchar **env)
rspamd_http_context_free (rspamd_main->http_ctx);
rspamd_log_close (rspamd_main->logger, TRUE);
rspamd_url_deinit ();
g_free (rspamd_main);
g_ptr_array_free (all_commands, TRUE);
ev_loop_destroy (rspamd_main->event_loop);
g_hash_table_unref (ucl_vars);
rspamd_mempool_delete (rspamd_main->server_pool);
g_free (rspamd_main);

return retcode;
}
Expand Down
5 changes: 3 additions & 2 deletions src/rspamd_proxy.c
Expand Up @@ -2230,6 +2230,9 @@ start_rspamd_proxy (struct rspamd_worker *worker)

ctx->http_ctx = rspamd_http_context_create (ctx->cfg, ctx->event_loop,
ctx->cfg->ups_ctx);
rspamd_mempool_add_destructor (ctx->cfg->cfg_pool,
(rspamd_mempool_destruct_t)rspamd_http_context_free,
ctx->http_ctx);

if (ctx->has_self_scan) {
/* Additional initialisation needed */
Expand Down Expand Up @@ -2263,9 +2266,7 @@ start_rspamd_proxy (struct rspamd_worker *worker)
rspamd_stat_close ();
}

struct rspamd_http_context *http_ctx = ctx->http_ctx;
REF_RELEASE (ctx->cfg);
rspamd_http_context_free (http_ctx);
rspamd_log_close (worker->srv->logger, TRUE);

exit (EXIT_SUCCESS);
Expand Down
5 changes: 3 additions & 2 deletions src/worker.c
Expand Up @@ -668,6 +668,9 @@ start_worker (struct rspamd_worker *worker)

ctx->http_ctx = rspamd_http_context_create (ctx->cfg, ctx->event_loop,
ctx->cfg->ups_ctx);
rspamd_mempool_add_destructor (ctx->cfg->cfg_pool,
(rspamd_mempool_destruct_t)rspamd_http_context_free,
ctx->http_ctx);
rspamd_worker_init_scanner (worker, ctx->event_loop, ctx->resolver,
&ctx->lang_det);
rspamd_lua_run_postloads (ctx->cfg->lua_state, ctx->cfg, ctx->event_loop,
Expand All @@ -677,9 +680,7 @@ start_worker (struct rspamd_worker *worker)
rspamd_worker_block_signals ();

rspamd_stat_close ();
struct rspamd_http_context *http_ctx = ctx->http_ctx;
REF_RELEASE (ctx->cfg);
rspamd_http_context_free (http_ctx);
rspamd_log_close (worker->srv->logger, TRUE);

exit (EXIT_SUCCESS);
Expand Down

0 comments on commit 3da3ad2

Please sign in to comment.