/* 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);
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);
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)
*/
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
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 */
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);
g_free (lp);
}
- g_free (cfg);
+ rspamd_mempool_delete (cfg->cfg_pool);
}
const ucl_object_t *
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;
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);
}
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);
}
}
}
}
+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)
{
}
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);
}
#endif
#endif
+ g_free (cache);
}
}
ZSTD_freeDStream (ctx->in_zstream);
}
+ rspamd_cryptobox_deinit (ctx->crypto_ctx);
+
g_free (ctx);
}
}
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];
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;
}
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 */
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);
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,
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);