]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Track more memory allocations in a task
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 Dec 2019 19:27:04 +0000 (19:27 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 Dec 2019 19:27:04 +0000 (19:27 +0000)
src/libmime/email_addr.c
src/libmime/message.c
src/libmime/mime_encoding.c
src/libmime/mime_headers.c
src/libmime/mime_parser.c
src/libserver/html.c
src/libserver/task.c
src/libstat/stat_process.c
src/libutil/mem_pool.c

index 24b1d0111a657822a505e2c272fe476404253113..4e09de6fb7ab8fec72057abff94a02ad49b547f0 100644 (file)
@@ -110,6 +110,7 @@ rspamd_email_address_add (rspamd_mempool_t *pool,
        guint nlen;
 
        elt = g_malloc0 (sizeof (*elt));
+       rspamd_mempool_notify_alloc (pool, sizeof (*elt));
 
        if (addr != NULL) {
                memcpy (elt, addr, sizeof (*addr));
@@ -132,6 +133,7 @@ rspamd_email_address_add (rspamd_mempool_t *pool,
                /* We need to unquote addr */
                nlen = elt->domain_len + elt->user_len + 2;
                elt->addr = g_malloc (nlen + 1);
+               rspamd_mempool_notify_alloc (pool, nlen + 1);
                elt->addr_len = rspamd_snprintf ((char *)elt->addr, nlen, "%*s@%*s",
                                (gint)elt->user_len, elt->user,
                                (gint)elt->domain_len, elt->domain);
@@ -143,6 +145,7 @@ rspamd_email_address_add (rspamd_mempool_t *pool,
                elt->name = rspamd_mime_header_decode (pool, name->str, name->len, NULL);
        }
 
+       rspamd_mempool_notify_alloc (pool, name->len);
        g_ptr_array_add (ar, elt);
 }
 
@@ -481,6 +484,7 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool,
                break;
        }
 
+       rspamd_mempool_notify_alloc (pool, cpy->len);
        g_string_free (ns, TRUE);
 
        return res;
index e99fc4af77367e81835246c5561eb7096aed83b2..95a1ab708e54c9e461f841a39bfa531fa1cbc694 100644 (file)
@@ -549,6 +549,8 @@ rspamd_normalize_text_part (struct rspamd_task *task,
        rspamd_mempool_add_destructor (task->task_pool,
                        (rspamd_mempool_destruct_t) free_byte_array_callback,
                        part->utf_stripped_content);
+       rspamd_mempool_notify_alloc (task->task_pool,
+                       part->utf_stripped_content->len);
        rspamd_mempool_add_destructor (task->task_pool,
                        (rspamd_mempool_destruct_t) rspamd_ptr_array_free_hard,
                        part->newlines);
index d98f96b8537d10e73797e950a4206f4e48bd131c..0ba0e0edd6d0a6f31e1e180c0582149990b7c256 100644 (file)
@@ -672,6 +672,8 @@ rspamd_mime_text_part_maybe_convert (struct rspamd_task *task,
        part_content = g_byte_array_sized_new (text_part->parsed.len);
        memcpy (part_content->data, text_part->parsed.begin, text_part->parsed.len);
        part_content->len = text_part->parsed.len;
+       rspamd_mempool_notify_alloc (task->task_pool,
+                       part_content->len);
        rspamd_mempool_add_destructor (task->task_pool,
                        (rspamd_mempool_destruct_t)g_byte_array_unref, part_content);
 
index e0c91c47858349eef2dec26f9c1dbb00066331fd..aed7575ebdfeaf3d97df0c555f31060774e8418e 100644 (file)
@@ -787,6 +787,7 @@ rspamd_mime_header_decode (rspamd_mempool_t *pool, const gchar *in,
        g_byte_array_free (token, TRUE);
        g_byte_array_free (decoded, TRUE);
        rspamd_mime_header_sanity_check (out);
+       rspamd_mempool_notify_alloc (pool, out->len);
        ret = g_string_free (out, FALSE);
        rspamd_mempool_add_destructor (pool, g_free, ret);
 
index 18c54d13b79d5a6bc9e064a576de8f6400ed1d00..d989a8e2ea608f988c234d0606ac4af3cffa8e5e 100644 (file)
@@ -539,6 +539,7 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
                        memcpy (parsed->str, part->raw_data.begin, parsed->len);
                        part->parsed_data.begin = parsed->str;
                        part->parsed_data.len = parsed->len;
+                       rspamd_mempool_notify_alloc (task->task_pool, parsed->len);
                        rspamd_mempool_add_destructor (task->task_pool,
                                        (rspamd_mempool_destruct_t)rspamd_fstring_free, parsed);
                }
@@ -555,6 +556,7 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
                        parsed->len = r;
                        part->parsed_data.begin = parsed->str;
                        part->parsed_data.len = parsed->len;
+                       rspamd_mempool_notify_alloc (task->task_pool, parsed->len);
                        rspamd_mempool_add_destructor (task->task_pool,
                                        (rspamd_mempool_destruct_t)rspamd_fstring_free, parsed);
                }
@@ -566,6 +568,7 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
                        parsed->len = part->raw_data.len;
                        part->parsed_data.begin = parsed->str;
                        part->parsed_data.len = parsed->len;
+                       rspamd_mempool_notify_alloc (task->task_pool, parsed->len);
                        rspamd_mempool_add_destructor (task->task_pool,
                                        (rspamd_mempool_destruct_t)rspamd_fstring_free, parsed);
                }
@@ -577,6 +580,7 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
                                parsed->str, &parsed->len);
                part->parsed_data.begin = parsed->str;
                part->parsed_data.len = parsed->len;
+               rspamd_mempool_notify_alloc (task->task_pool, parsed->len);
                rspamd_mempool_add_destructor (task->task_pool,
                                (rspamd_mempool_destruct_t)rspamd_fstring_free, parsed);
                break;
@@ -584,6 +588,7 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
                parsed = rspamd_fstring_sized_new (part->raw_data.len / 4 * 3 + 12);
                r = rspamd_decode_uue_buf (part->raw_data.begin, part->raw_data.len,
                                parsed->str, parsed->allocated);
+               rspamd_mempool_notify_alloc (task->task_pool, parsed->len);
                rspamd_mempool_add_destructor (task->task_pool,
                                (rspamd_mempool_destruct_t)rspamd_fstring_free, parsed);
                if (r != -1) {
@@ -597,6 +602,7 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
                        part->cte = RSPAMD_CTE_8BIT;
                        parsed->len = MIN (part->raw_data.len, parsed->allocated);
                        memcpy (parsed->str, part->raw_data.begin, parsed->len);
+                       rspamd_mempool_notify_alloc (task->task_pool, parsed->len);
                        part->parsed_data.begin = parsed->str;
                        part->parsed_data.len = parsed->len;
                }
index 5bb3ca05bab6ec6b38ef01a9d9b7fa77d4a0899f..d9cddb468c4d4e0e6a761a2c9391fdc74e8f9419 100644 (file)
@@ -1801,6 +1801,7 @@ rspamd_html_process_img_tag (rspamd_mempool_t *pool, struct html_tag *tag,
 
        if (hc->images == NULL) {
                hc->images = g_ptr_array_sized_new (4);
+               rspamd_mempool_notify_alloc (pool, 4 * sizeof (gpointer) + sizeof (GPtrArray));
                rspamd_mempool_add_destructor (pool, rspamd_ptr_array_free_hard,
                                hc->images);
        }
@@ -2370,6 +2371,7 @@ rspamd_html_process_block_tag (rspamd_mempool_t *pool, struct html_tag *tag,
 
        if (hc->blocks == NULL) {
                hc->blocks = g_ptr_array_sized_new (64);
+               rspamd_mempool_notify_alloc (pool, 64 * sizeof (gpointer) + sizeof (GPtrArray));
                rspamd_mempool_add_destructor (pool, rspamd_ptr_array_free_hard,
                                hc->blocks);
        }
index ccd959920beb70c9715b9ac47238f75a81f6be4c..634ebb392339c2b8a559dc85f105b380d4ccdb68 100644 (file)
@@ -1158,6 +1158,7 @@ rspamd_task_log_metric_res (struct rspamd_task *task,
                        rspamd_mempool_add_destructor (task->task_pool,
                                        (rspamd_mempool_destruct_t)rspamd_fstring_free,
                                        symbuf);
+                       rspamd_mempool_notify_alloc (task->task_pool, symbuf->len);
                        res.begin = symbuf->str;
                        res.len = symbuf->len;
                        break;
@@ -1203,6 +1204,7 @@ rspamd_task_log_metric_res (struct rspamd_task *task,
                        rspamd_mempool_add_destructor (task->task_pool,
                                        (rspamd_mempool_destruct_t) rspamd_fstring_free,
                                        symbuf);
+                       rspamd_mempool_notify_alloc (task->task_pool, symbuf->len);
                        res.begin = symbuf->str;
                        res.len = symbuf->len;
                        break;
index 603e0ac963d6bb2da2b813085827069361022480..6bd17f38f0269224de38406b5e41610d08e30ef3 100644 (file)
@@ -142,6 +142,7 @@ rspamd_stat_process_tokenize (struct rspamd_stat_ctx *st_ctx,
        task->tokens = g_ptr_array_sized_new (reserved_len);
        rspamd_mempool_add_destructor (task->task_pool,
                        rspamd_ptr_array_free_hard, task->tokens);
+       rspamd_mempool_notify_alloc (task->task_pool, reserved_len * sizeof (gpointer));
        pdiff = rspamd_mempool_get_variable (task->task_pool, "parts_distance");
 
        PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, text_parts), i, part) {
index f2272fa7c82b520b99c0505f725916e45183b2b6..df8c3cb070ff0ad8f0b7ad724ee90f5012eea571 100644 (file)
@@ -445,10 +445,10 @@ RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR
 void
 rspamd_mempool_notify_alloc_ (rspamd_mempool_t *pool, gsize size, const gchar *loc)
 {
-       GHashTable *debug_tbl = *(GHashTable **)(((guchar *)pool + sizeof (*pool)));
-       gpointer ptr;
+       if (pool && G_UNLIKELY (pool->priv->flags & RSPAMD_MEMPOOL_DEBUG)) {
+               GHashTable *debug_tbl = *(GHashTable **)(((guchar *)pool + sizeof (*pool)));
+               gpointer ptr;
 
-       if (G_UNLIKELY (pool->priv->flags & RSPAMD_MEMPOOL_DEBUG)) {
                ptr = g_hash_table_lookup (debug_tbl, loc);
 
                if (ptr) {