From 69f83713b0fe68333c83a73bbca3a1280f23a7bb Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 22 Apr 2016 13:34:42 +0100 Subject: [PATCH] [CritFix] Plug memory leak in headers getting code --- src/libmime/message.c | 10 ++++++++++ src/libmime/message.h | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/libmime/message.c b/src/libmime/message.c index 6b6af40e3..cd18f6ce4 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -1956,6 +1956,9 @@ rspamd_message_get_header_array (struct rspamd_task *task, g_ptr_array_add (ret, cur); } + rspamd_mempool_add_destructor (task->task_pool, + (rspamd_mempool_destruct_t)rspamd_ptr_array_free_hard, ret); + return ret; } @@ -1982,6 +1985,10 @@ rspamd_message_get_mime_header_array (struct rspamd_task *task, } } + if (nelems == 0) { + return NULL; + } + ret = g_ptr_array_sized_new (nelems); for (i = 0; i < task->parts->len; i ++) { @@ -1999,5 +2006,8 @@ rspamd_message_get_mime_header_array (struct rspamd_task *task, } } + rspamd_mempool_add_destructor (task->task_pool, + (rspamd_mempool_destruct_t)rspamd_ptr_array_free_hard, ret); + return ret; } diff --git a/src/libmime/message.h b/src/libmime/message.h index 367f0000c..4f8f27b0b 100644 --- a/src/libmime/message.h +++ b/src/libmime/message.h @@ -78,7 +78,7 @@ struct raw_header { */ gboolean rspamd_message_parse (struct rspamd_task *task); -/* +/** * Get a list of header's values with specified header's name using raw headers * @param task worker task structure * @param field header's name @@ -89,12 +89,26 @@ GList * rspamd_message_get_header (struct rspamd_task *task, const gchar *field, gboolean strong); +/** + * Get an array of header's values with specified header's name using raw headers + * @param task worker task structure + * @param field header's name + * @param strong if this flag is TRUE header's name is case sensitive, otherwise it is not + * @return An array of header's values or NULL. It is NOT permitted to free array or values. + */ GPtrArray *rspamd_message_get_header_array (struct rspamd_task *task, const gchar *field, gboolean strong); - +/** + * Get an array of mime parts header's values with specified header's name using raw headers + * @param task worker task structure + * @param field header's name + * @param strong if this flag is TRUE header's name is case sensitive, otherwise it is not + * @return An array of header's values or NULL. It is NOT permitted to free array or values. + */ GPtrArray *rspamd_message_get_mime_header_array (struct rspamd_task *task, const gchar *field, gboolean strong); + #endif -- 2.39.5