]> source.dussan.org Git - rspamd.git/commitdiff
Add destruction routine for exprs and atoms.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 17 Mar 2015 15:08:20 +0000 (15:08 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 17 Mar 2015 15:08:20 +0000 (15:08 +0000)
src/libutil/expression.c
src/libutil/expression.h

index b5b4dce5fd63bbc516ecf340ebb71ec963936b0c..67db9e7deedee7184560a43f9618ca7656ee09e0 100644 (file)
@@ -251,6 +251,31 @@ rspamd_expr_str_to_op (const gchar *a, const gchar *end, const gchar **next)
        return op;
 }
 
+static void
+rspamd_expression_destroy (struct rspamd_expression *expr)
+{
+       guint i;
+       struct rspamd_expression_elt *elt;
+
+       if (expr != NULL) {
+
+               if (expr->subr->destroy) {
+                       /* Free atoms */
+                       for (i = 0; i < expr->expressions->len; i ++) {
+                               elt = &g_array_index (expr->expressions,
+                                               struct rspamd_expression_elt, i);
+
+                               if (elt->type == ELT_ATOM) {
+                                       expr->subr->destroy (elt->p.atom);
+                               }
+                       }
+               }
+
+               g_array_free (expr->expressions, TRUE);
+               g_array_free (expr->expression_stack, TRUE);
+       }
+}
+
 gboolean
 rspamd_parse_expression (const gchar *line, gsize len,
                struct rspamd_atom_subr *subr, gpointer subr_data,
@@ -302,7 +327,8 @@ rspamd_parse_expression (const gchar *line, gsize len,
                                /*
                                 * First of all, we check some pre-conditions:
                                 * 1) if we have 'and ' or 'or ' or 'not ' strings, they are op
-                                * 2) if we have full numeric string, then we check for the following:
+                                * 2) if we have full numeric string, then we check for
+                                * the following expression:
                                 *  ^\d+\s*[><]$
                                 */
                                if ((gulong)(end - p) > sizeof ("and ") &&
@@ -470,6 +496,11 @@ rspamd_parse_expression (const gchar *line, gsize len,
 
        if (*target) {
                *target = e;
+               rspamd_mempool_add_destructor (pool,
+                       (rspamd_mempool_destruct_t)rspamd_expression_destroy, e);
+       }
+       else {
+               rspamd_expression_destroy (e);
        }
 
        return TRUE;
index 798d3a48c3b9ec400b8a78dabbbfd785be3e7dd6..4179424c664feb6d02dc273c31848927902f3889 100644 (file)
@@ -47,6 +47,7 @@ struct rspamd_atom_subr {
        gint (*process) (gpointer input, rspamd_expression_atom_t *atom);
        /* Calculates the relative priority of the expression */
        gint (*priority) (rspamd_expression_atom_t *atom);
+       void (*destroy) (rspamd_expression_atom_t *atom);
 };
 
 /* Opaque structure */