]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Further static leaks removal
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 27 Sep 2019 14:28:07 +0000 (15:28 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 27 Sep 2019 14:28:07 +0000 (15:28 +0100)
12 files changed:
src/controller.c
src/libcryptobox/cryptobox.c
src/libcryptobox/cryptobox.h
src/libserver/cfg_utils.c
src/libutil/http_context.c
src/libutil/logger.c
src/libutil/regexp.c
src/libutil/util.c
src/rspamadm/configtest.c
src/rspamadm/rspamadm.c
src/rspamd_proxy.c
src/worker.c

index 2f76bcc6904a5a036d9d0a2e164dd42968c3f704..474e7ec9264c9914f3ac64f6384eb76d112e0b82 100644 (file)
@@ -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);
@@ -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);
index 0b4ebe614d566e47abc922648dfea9fea488c259..e4549096faf8ab2f931396d5bdeaa2ea26f0136f 100644 (file)
@@ -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)
index 3924d7fe3e0daa5f0392f8f3438e6c0d507a2cc7..61395d11fb4791d9164eeacbe5517894cbb6704b 100644 (file)
@@ -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
index 25015c269690338c25aaaf779909c3d916d71384..dd2578c918db828d5fc8c86640aaaca99aae1600 100644 (file)
@@ -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 */
@@ -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);
@@ -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 *
index f2ecaa037550a2acd3ecbe66715bb73780f18db8..9e2b097980b2e3a8ec5055a1581aa085e81fbe4b 100644 (file)
@@ -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;
@@ -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);
        }
index 8238886dab6dcaf7b8924285a28d450b352c8cd9..1a60b9e3f62e9e64253087f26c078438b36a77ba 100644 (file)
@@ -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);
        }
 }
 
@@ -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)
 {
@@ -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);
index 6f449539ff55f0cd087a7ba4513a3f51988cb3b0..4ce9c4218a4089e7ced77e6b1a81df0fc23d9869 100644 (file)
@@ -1055,6 +1055,7 @@ rspamd_regexp_cache_destroy (struct rspamd_regexp_cache *cache)
                }
 #endif
 #endif
+               g_free (cache);
        }
 }
 
index 7877582c27dd5222a51da4fd5fc3e0c9c3e71229..f528a321edbf692fa58e43cc76bb047fef677c51 100644 (file)
@@ -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);
        }
 }
index 6c07959dbc6d86fe6da29b9ae484372a421186f4..1ebabe48bcdc932ce9921df0c649417104d2e584 100644 (file)
@@ -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];
index 3a2bb4c53477efd8bd5ab73169d624555473d6eb..2487207ef2f94545a3aa96c644396f9b151a72dd 100644 (file)
@@ -619,8 +619,11 @@ end:
        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;
 }
index 6b1eec2377fa756833523040740a316b3c92564f..be3395273f765404c3a3ba2c1d108e126963b81d 100644 (file)
@@ -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 */
@@ -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);
index 59f7f6e9e2bd500f8132355cf6714e265fd5a7cb..0ed298181f939004df769111bf105a056b1ef6f5 100644 (file)
@@ -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,
@@ -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);