]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Plug memory leak in expressions parsing during reload
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 17 Jan 2017 16:54:33 +0000 (16:54 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 17 Jan 2017 16:54:33 +0000 (16:54 +0000)
src/libmime/mime_expressions.c
src/libutil/expression.c

index 637cccad3ecd89ec135f67c8b33947613eb93e26..e8a3134c7a6bafd05ea5799efe27ed6887123d42 100644 (file)
@@ -449,6 +449,8 @@ rspamd_mime_expr_parse_regexp_atom (rspamd_mempool_t * pool, const gchar *line,
        }
 
        rspamd_regexp_set_ud (result->regexp, result);
+       rspamd_mempool_add_destructor (pool,
+                       (rspamd_mempool_destruct_t)rspamd_regexp_unref, result->regexp);
 
        *dend = '/';
 
@@ -706,9 +708,9 @@ set:
                return NULL;
        }
 
-       mime_atom = g_slice_alloc (sizeof (*mime_atom));
+       mime_atom = rspamd_mempool_alloc (pool, sizeof (*mime_atom));
        mime_atom->type = type;
-       mime_atom->str = g_malloc (p - line + 1);
+       mime_atom->str = rspamd_mempool_alloc (pool, p - line + 1);
        rspamd_strlcpy (mime_atom->str, line, p - line + 1);
 
        if (type == MIME_ATOM_REGEXP) {
@@ -788,8 +790,6 @@ set:
        return a;
 
 err:
-       g_free (mime_atom->str);
-       g_slice_free1 (sizeof (*mime_atom), mime_atom);
 
        return NULL;
 }
@@ -889,8 +889,6 @@ rspamd_mime_expr_destroy (rspamd_expression_atom_t *atom)
                        }
                        g_array_free (mime_atom->d.func->args, TRUE);
                }
-               /* XXX: regexp shouldn't be special */
-               g_slice_free1 (sizeof (*mime_atom), mime_atom);
        }
 }
 
index 618adad49f31632defd0853a2b72640bb1f0ba82..e42800608ffbd37cd526b25a488114533cc8b327 100644 (file)
@@ -856,6 +856,9 @@ rspamd_parse_expression (const gchar *line, gsize len,
        return TRUE;
 
 err:
+       g_ptr_array_free (operand_stack, TRUE);
+       rspamd_expression_destroy (e);
+
        return FALSE;
 }