]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Fix some memory issues
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 Nov 2015 12:20:03 +0000 (12:20 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 Nov 2015 12:20:03 +0000 (12:20 +0000)
src/libserver/fuzzy_backend.c
src/libutil/upstream.c

index cbc04756f3a9f1cf4548bf02560314f8307cfaa3..86902d05c9289fabd30faca80546979fbb3d6e92 100644 (file)
@@ -685,15 +685,11 @@ rspamd_fuzzy_backend_sync (struct rspamd_fuzzy_backend *backend,
                gint64 number;
        };
 
-       if (backend == NULL) {
-               return FALSE;
-       }
-
        /* Do not do more than 5k ops per step */
        const guint64 max_changes = 5000;
        gboolean ret = FALSE;
        gint64 expire_lim, expired;
-       gint rc, i;
+       gint rc, i, orphaned_cnt = 0;
        GError *err = NULL;
        static const gchar orphaned_shingles[] = "SELECT shingles.value,shingles.number "
                        "FROM shingles "
@@ -704,6 +700,11 @@ rspamd_fuzzy_backend_sync (struct rspamd_fuzzy_backend *backend,
        GArray *orphaned;
        struct orphaned_shingle_elt orphaned_elt, *pelt;
 
+
+       if (backend == NULL) {
+               return FALSE;
+       }
+
        /* Perform expire */
        if (expire > 0) {
                expire_lim = time (NULL) - expire;
@@ -779,13 +780,14 @@ rspamd_fuzzy_backend_sync (struct rspamd_fuzzy_backend *backend,
                                }
 
                                sqlite3_finalize (stmt);
+                               orphaned_cnt = orphaned->len;
 
-                               if (orphaned->len > 0) {
+                               if (orphaned_cnt > 0) {
                                        msg_info_fuzzy_backend (
                                                        "going to delete %ud orphaned shingles",
-                                                       orphaned->len);
+                                                       orphaned_cnt);
                                        /* Need to delete orphaned elements */
-                                       for (i = 0; i < (gint) orphaned->len; i++) {
+                                       for (i = 0; i < (gint) orphaned_cnt; i++) {
                                                pelt = &g_array_index (orphaned,
                                                                struct orphaned_shingle_elt,
                                                                i);
@@ -795,6 +797,7 @@ rspamd_fuzzy_backend_sync (struct rspamd_fuzzy_backend *backend,
                                        }
                                }
 
+
                                g_array_free (orphaned, TRUE);
                        }
 
@@ -804,7 +807,7 @@ rspamd_fuzzy_backend_sync (struct rspamd_fuzzy_backend *backend,
                        if (ret == SQLITE_OK) {
                                msg_info_fuzzy_backend (
                                                "deleted %ud orphaned shingles",
-                                               orphaned->len);
+                                               orphaned_cnt);
                        }
                        else {
                                msg_warn_fuzzy_backend (
index fd8debfe49d3ab6d1041b076349de2308482d38c..9eecb85cf8041257c8f421bbabe613e5f3d1ba53 100644 (file)
@@ -463,7 +463,7 @@ rspamd_upstream_dtor (struct upstream *up)
                g_queue_delete_link (up->ctx->upstreams, up->ctx_pos);
                REF_RELEASE (up->ctx);
        }
-       g_list_free (up->ctx_pos);
+
        g_slice_free1 (sizeof (*up), up);
 }