From: Vsevolod Stakhov Date: Wed, 29 Aug 2018 22:17:44 +0000 (+0100) Subject: [Minor] Fix byte array allocation X-Git-Tag: 1.8.0~197 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=112ed7966d7fcaf7f0a16a79b0af51e7d339e744;p=thirdparty%2Frspamd.git [Minor] Fix byte array allocation --- diff --git a/src/libmime/mime_encoding.c b/src/libmime/mime_encoding.c index 2f0df38eb0..d3f255740b 100644 --- a/src/libmime/mime_encoding.c +++ b/src/libmime/mime_encoding.c @@ -651,18 +651,17 @@ rspamd_mime_text_part_maybe_convert (struct rspamd_task *task, GByteArray *part_content; rspamd_ftok_t charset_tok; struct rspamd_mime_part *part = text_part->mime_part; - gdouble t1, t2; - t1 = rspamd_get_ticks (TRUE); if (rspamd_str_has_8bit (text_part->raw.begin, text_part->raw.len)) { text_part->flags |= RSPAMD_MIME_TEXT_PART_FLAG_8BIT; } - part_content = rspamd_mempool_alloc0 (task->task_pool, sizeof (GByteArray)); - part_content->data = rspamd_mempool_alloc (task->task_pool, - text_part->parsed.len); + /* Allocate copy storage */ + 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_add_destructor (task->task_pool, + (rspamd_mempool_destruct_t)g_byte_array_unref, part_content); if (rspamd_str_has_8bit (text_part->parsed.begin, text_part->parsed.len)) { text_part->flags |= RSPAMD_MIME_TEXT_PART_FLAG_8BIT_ENCODED; @@ -729,8 +728,6 @@ rspamd_mime_text_part_maybe_convert (struct rspamd_task *task, rspamd_mime_text_part_ucs_from_utf (task, text_part); rspamd_mime_text_part_normalise (task, text_part); rspamd_mime_text_part_maybe_renormalise (task, text_part); - t2 = rspamd_get_ticks (TRUE); - msg_err_task ("conversion time: %.0f ticks", t2 - t1); return; } @@ -752,6 +749,4 @@ rspamd_mime_text_part_maybe_convert (struct rspamd_task *task, } SET_PART_UTF (text_part); - t2 = rspamd_get_ticks (TRUE); - msg_err_task ("conversion time: %.0f ticks", t2 - t1); }