]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] More leaks...
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 18 Jan 2017 16:09:50 +0000 (16:09 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 18 Jan 2017 16:09:50 +0000 (16:09 +0000)
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/libutil/map.c
src/libutil/upstream.c
src/lua/lua_map.c
src/lua/lua_regexp.c
src/plugins/fuzzy_check.c
src/rspamd.c

index e80eae7dd0b82c3644148c0c20e8f19b044bdba2..48ecb94dafc6cf536cfa1d698e6fb9b1f12cf72b 100644 (file)
@@ -39,7 +39,7 @@
 
 struct rspamd_rcl_default_handler_data {
        struct rspamd_rcl_struct_parser pd;
-       const gchar *key;
+       gchar *key;
        rspamd_rcl_default_handler_t handler;
        UT_hash_handle hh;
 };
@@ -1185,6 +1185,7 @@ rspamd_rcl_statfile_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
 
        if (rspamd_rcl_section_parse_defaults (cfg, section, pool, obj, st, err)) {
                ccf->statfiles = g_list_prepend (ccf->statfiles, st);
+
                if (st->label != NULL) {
                        labels = g_hash_table_lookup (ccf->labels, st->label);
                        if (labels != NULL) {
@@ -1698,13 +1699,13 @@ rspamd_rcl_add_default_handler (struct rspamd_rcl_section *section,
                gint flags,
                const gchar *doc_string)
 {
-       struct rspamd_rcl_default_handler_data *new;
+       struct rspamd_rcl_default_handler_data *nhandler;
 
-       new = g_slice_alloc0 (sizeof (struct rspamd_rcl_default_handler_data));
-       new->key = name;
-       new->handler = handler;
-       new->pd.offset = offset;
-       new->pd.flags = flags;
+       nhandler = g_slice_alloc0 (sizeof (struct rspamd_rcl_default_handler_data));
+       nhandler->key = g_strdup (name);
+       nhandler->handler = handler;
+       nhandler->pd.offset = offset;
+       nhandler->pd.flags = flags;
 
        if (section->doc_ref != NULL) {
                rspamd_rcl_add_doc_obj (section->doc_ref,
@@ -1717,9 +1718,9 @@ rspamd_rcl_add_default_handler (struct rspamd_rcl_section *section,
                                0);
        }
 
-       HASH_ADD_KEYPTR (hh, section->default_parser, new->key, strlen (
-                       new->key), new);
-       return new;
+       HASH_ADD_KEYPTR (hh, section->default_parser, nhandler->key, strlen (
+                       nhandler->key), nhandler);
+       return nhandler;
 }
 
 struct rspamd_rcl_section *
@@ -3019,6 +3020,9 @@ rspamd_rcl_parse_struct_pubkey (rspamd_mempool_t *pool,
                return FALSE;
        }
 
+       rspamd_mempool_add_destructor (pool,
+                       (rspamd_mempool_destruct_t)rspamd_pubkey_unref, pk);
+
        return TRUE;
 }
 
@@ -3462,6 +3466,7 @@ static void
 rspamd_rcl_section_free (gpointer p)
 {
        struct rspamd_rcl_section *top = p, *cur, *tmp;
+       struct rspamd_rcl_default_handler_data *dh, *dhtmp;
 
        HASH_ITER (hh, top, cur, tmp) {
                HASH_DEL (top, cur);
@@ -3470,6 +3475,12 @@ rspamd_rcl_section_free (gpointer p)
                        rspamd_rcl_section_free (cur->subsections);
                }
 
+               HASH_ITER (hh, cur->default_parser, dh, dhtmp) {
+                       HASH_DEL (cur->default_parser, dh);
+                       g_free (dh->key);
+                       g_slice_free1 (sizeof (*dh), dh);
+               }
+
                ucl_object_unref (cur->doc_ref);
                g_slice_free1 (sizeof (*cur), cur);
        }
index 8a8138ebfa50a2cd53e9016c81f6eea400fb6958..12a13cd9b1b9298c647426b32c6a3726d9d17407 100644 (file)
@@ -120,9 +120,7 @@ rspamd_config_new (void)
        cfg->max_diff = 20480;
 
        cfg->metrics = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
-       if (cfg->c_modules == NULL) {
-               cfg->c_modules = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
-       }
+       cfg->c_modules = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
        cfg->composite_symbols =
                g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
        cfg->classifiers_symbols = g_hash_table_new (rspamd_str_hash,
@@ -209,6 +207,7 @@ rspamd_config_free (struct rspamd_config *cfg)
 
        g_list_free (cfg->classifiers);
        g_list_free (cfg->metrics_list);
+       g_list_free (cfg->workers);
        rspamd_symbols_cache_destroy (cfg->cache);
 #ifdef WITH_HIREDIS
        if (cfg->redis_pool) {
index 6a1e76fcdf41f9382a1caef66e8b3472235a5f91..af76c6979363b867239afe2f65fe19a93e2f04c6 100644 (file)
@@ -1375,6 +1375,10 @@ rspamd_map_backend_dtor (struct rspamd_map_backend *bk)
                }
        }
 
+       if (bk->trusted_pubkey) {
+               rspamd_pubkey_unref (bk->trusted_pubkey);
+       }
+
        g_slice_free1 (sizeof (*bk), bk);
 }
 
@@ -1520,7 +1524,7 @@ rspamd_map_add (struct rspamd_config *cfg,
                return NULL;
        }
 
-       map = g_slice_alloc0 (sizeof (struct rspamd_map));
+       map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_map));
        map->read_callback = read_callback;
        map->fin_callback = fin_callback;
        map->user_data = user_data;
@@ -1531,12 +1535,14 @@ rspamd_map_add (struct rspamd_config *cfg,
        map->cache =
                        rspamd_mempool_alloc0_shared (cfg->cfg_pool, sizeof (*map->cache));
        map->backends = g_ptr_array_sized_new (1);
+       rspamd_mempool_add_destructor (cfg->cfg_pool, rspamd_ptr_array_free_hard,
+                       map->backends);
        g_ptr_array_add (map->backends, bk);
-       map->name = g_strdup (map_line);
+       map->name = rspamd_mempool_strdup (cfg->cfg_pool, map_line);
        map->poll_timeout = cfg->map_timeout;
 
        if (description != NULL) {
-               map->description = g_strdup (description);
+               map->description = rspamd_mempool_strdup (cfg->cfg_pool, description);
        }
 
        rspamd_map_calculate_hash (map);
@@ -1568,7 +1574,7 @@ rspamd_map_add_from_ucl (struct rspamd_config *cfg,
                                read_callback, fin_callback, user_data);
        }
 
-       map = g_slice_alloc0 (sizeof (struct rspamd_map));
+       map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_map));
        map->read_callback = read_callback;
        map->fin_callback = fin_callback;
        map->user_data = user_data;
@@ -1579,10 +1585,12 @@ rspamd_map_add_from_ucl (struct rspamd_config *cfg,
        map->cache =
                                rspamd_mempool_alloc0_shared (cfg->cfg_pool, sizeof (*map->cache));
        map->backends = g_ptr_array_new ();
+       rspamd_mempool_add_destructor (cfg->cfg_pool, rspamd_ptr_array_free_hard,
+                       map->backends);
        map->poll_timeout = cfg->map_timeout;
 
        if (description) {
-               map->description = g_strdup (description);
+               map->description = rspamd_mempool_strdup (cfg->cfg_pool, description);
        }
 
        if (ucl_object_type (obj) == UCL_ARRAY) {
@@ -1699,10 +1707,6 @@ rspamd_map_add_from_ucl (struct rspamd_config *cfg,
        return map;
 
 err:
-       g_ptr_array_free (map->backends, TRUE);
-       g_free (map->name);
-       g_free (map->description);
-       g_slice_free1 (sizeof (*map), map);
 
        return NULL;
 }
index 0576525d9d4595cfc73c8ff65a6fd270856af970..4e437d41672daa8c34ed7350c6c28e8b6354270f 100644 (file)
@@ -654,16 +654,18 @@ rspamd_upstreams_parse_line (struct upstream_list *ups,
 
        while (p < end) {
                len = strcspn (p, separators);
+
                if (len > 0) {
                        tmp = g_malloc (len + 1);
                        rspamd_strlcpy (tmp, p, len + 1);
+
                        if (rspamd_upstreams_add_upstream (ups, tmp, def_port, data)) {
                                ret = TRUE;
                        }
-                       else {
-                               g_free (tmp);
-                       }
+
+                       g_free (tmp);
                }
+
                p += len;
                /* Skip separators */
                p += strspn (p, separators);
index 581c4b85b8c7ae2634daca571b9bdfb2e8e42da1..0b271affeb8ceca1f2d8a76c453cf836526103c1 100644 (file)
@@ -417,15 +417,13 @@ lua_config_add_map (lua_State *L)
                }
                else if (strcmp (type, "set") == 0) {
                        map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*map));
-                       map->data.hash = g_hash_table_new (rspamd_strcase_hash,
-                                       rspamd_strcase_equal);
+                       map->data.hash = NULL;
                        map->type = RSPAMD_LUA_MAP_SET;
 
                        if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
                                        rspamd_hosts_read,
                                        rspamd_hosts_fin,
                                        (void **)&map->data.hash)) == NULL) {
-                               g_hash_table_destroy (map->data.hash);
                                lua_pushnil (L);
                                ucl_object_unref (map_obj);
 
@@ -434,15 +432,13 @@ lua_config_add_map (lua_State *L)
                }
                else if (strcmp (type, "map") == 0 || strcmp (type, "hash") == 0) {
                        map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*map));
-                       map->data.hash = g_hash_table_new (rspamd_strcase_hash,
-                                       rspamd_strcase_equal);
+                       map->data.hash = NULL;
                        map->type = RSPAMD_LUA_MAP_HASH;
 
                        if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
                                        rspamd_kv_list_read,
                                        rspamd_kv_list_fin,
                                        (void **)&map->data.hash)) == NULL) {
-                               g_hash_table_destroy (map->data.hash);
                                lua_pushnil (L);
                                ucl_object_unref (map_obj);
 
@@ -451,14 +447,13 @@ lua_config_add_map (lua_State *L)
                }
                else if (strcmp (type, "radix") == 0) {
                        map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*map));
-                       map->data.radix = radix_create_compressed ();
+                       map->data.radix = NULL;
                        map->type = RSPAMD_LUA_MAP_RADIX;
 
                        if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
                                        rspamd_radix_read,
                                        rspamd_radix_fin,
                                        (void **)&map->data.radix)) == NULL) {
-                               radix_destroy_compressed (map->data.radix);
                                lua_pushnil (L);
                                ucl_object_unref (map_obj);
 
index 1e6122b2ee62f77ec3cf1677015554c73ba54cd9..1640f8023ec35007380a6ad30e6af882a2026e3b 100644 (file)
@@ -745,6 +745,10 @@ luaopen_regexp (lua_State * L)
        luaL_register (L, NULL, regexplib_m);
        rspamd_lua_add_preload (L, "rspamd_regexp", lua_load_regexp);
 
-       regexp_static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+       if (regexp_static_pool == NULL) {
+               regexp_static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
+                               "regexp_lua_pool");
+       }
+
        lua_settop (L, 0);
 }
index e6a7b1bc1093d44b98c757d5dc509db3b606f71d..1088fe639908488aeb2655f2f1477f56c7ad9c21 100644 (file)
@@ -242,6 +242,8 @@ parse_mime_types (const gchar *str)
        strvec = g_strsplit_set (str, ",", 0);
        num = g_strv_length (strvec);
        res = g_ptr_array_sized_new (num);
+       rspamd_mempool_add_destructor (fuzzy_module_ctx->fuzzy_pool,
+                       rspamd_ptr_array_free_hard, res);
 
        for (i = 0; i < num; i++) {
                g_strstrip (strvec[i]);
@@ -252,12 +254,21 @@ parse_mime_types (const gchar *str)
                        type->type_re = rspamd_regexp_from_glob (strvec[i], p - strvec[i],
                                        NULL);
                        type->subtype_re = rspamd_regexp_from_glob (p + 1, 0, NULL);
+                       rspamd_mempool_add_destructor (fuzzy_module_ctx->fuzzy_pool,
+                                               (rspamd_mempool_destruct_t)rspamd_regexp_unref,
+                                               type->type_re);
+                       rspamd_mempool_add_destructor (fuzzy_module_ctx->fuzzy_pool,
+                                       (rspamd_mempool_destruct_t)rspamd_regexp_unref,
+                                       type->subtype_re);
                        g_ptr_array_add (res, type);
                }
                else {
                        type = rspamd_mempool_alloc (fuzzy_module_ctx->fuzzy_pool,
                                                        sizeof (struct fuzzy_mime_type));
                        type->type_re = rspamd_regexp_from_glob (strvec[i], 0, NULL);
+                       rspamd_mempool_add_destructor (fuzzy_module_ctx->fuzzy_pool,
+                                       (rspamd_mempool_destruct_t)rspamd_regexp_unref,
+                                       type->type_re);
                        type->subtype_re = NULL;
                        g_ptr_array_add (res, type);
                }
index f13ec9454b86f3f489104dde100129a0927e1591..19811238c38274c44e51f9964117eba63f616d5e 100644 (file)
@@ -272,6 +272,7 @@ reread_config (struct rspamd_main *rspamd_main)
        gchar *cfg_file;
 
        tmp_cfg = rspamd_config_new ();
+       g_hash_table_unref (tmp_cfg->c_modules);
        tmp_cfg->c_modules = g_hash_table_ref (rspamd_main->cfg->c_modules);
        tmp_cfg->libs_ctx = rspamd_main->cfg->libs_ctx;
        REF_RETAIN (tmp_cfg->libs_ctx);
@@ -640,6 +641,8 @@ spawn_workers (struct rspamd_main *rspamd_main, struct event_base *ev_base)
                        }
                }
        }
+
+       g_ptr_array_free (seen_mandatory_workers);
 }
 
 static void
@@ -997,6 +1000,7 @@ rspamd_cld_handler (gint signo, short what, gpointer arg)
                        close (cur->control_pipe[0]);
                        close (cur->srv_pipe[0]);
                        REF_RELEASE (cur->cf);
+                       g_ptr_array_free (cur->finish_actions, TRUE);
                        g_free (cur);
                }
                else {