aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-27 13:47:00 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-27 13:47:00 +0300
commitfdccb337ed73f14b204721cf464ca03a7eca49b6 (patch)
tree6efd3483f969be2e63d6f285d281adbab82fff0f
parent251d13cc56cdf625bafac9db008d85abe0fa893c (diff)
downloadrspamd-fdccb337ed73f14b204721cf464ca03a7eca49b6.tar.gz
rspamd-fdccb337ed73f14b204721cf464ca03a7eca49b6.zip
* Fix 2 memory leaks
* Fix uptime command output
-rw-r--r--src/controller.c1
-rw-r--r--src/expressions.c160
-rw-r--r--src/mem_pool.c1
-rw-r--r--src/worker.c3
4 files changed, 96 insertions, 69 deletions
diff --git a/src/controller.c b/src/controller.c
index d82cc726e..5a444b275 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -237,6 +237,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control
else {
hours = uptime / 3600;
minutes = uptime / 60 - hours * 3600;
+ uptime -= hours * 3600 + minutes * 60;
r = snprintf (out_buf, sizeof (out_buf), "%d hour%s %d minite%s %d second%s" CRLF,
hours, hours > 1 ? "s" : " ",
minutes, minutes > 1 ? "s" : " ",
diff --git a/src/expressions.c b/src/expressions.c
index b115eba72..683e13dd8 100644
--- a/src/expressions.c
+++ b/src/expressions.c
@@ -689,6 +689,7 @@ rspamd_content_type_compare_param (struct worker_task *task, GList *args)
const char *param_data;
struct rspamd_regexp *re;
struct expression_argument *arg;
+ GMimeObject *part;
const GMimeContentType *ct;
if (args == NULL) {
@@ -705,31 +706,36 @@ rspamd_content_type_compare_param (struct worker_task *task, GList *args)
arg = args->data;
param_pattern = arg->data;
- ct = g_mime_object_get_content_type (GMIME_OBJECT (g_mime_message_get_mime_part (task->message)));
- if ((param_data = g_mime_content_type_get_parameter (ct, param_name)) == NULL) {
- return FALSE;
- }
-
- if (*param_pattern == '/') {
- /* This is regexp, so compile and create g_regexp object */
- if ((re = re_cache_check (param_pattern)) == NULL) {
- re = parse_regexp (task->task_pool, param_pattern);
- if (re == NULL) {
- msg_warn ("rspamd_content_type_compare_param: cannot compile regexp for function");
- return FALSE;
- }
- re_cache_add (param_pattern, re);
+ part = g_mime_message_get_mime_part (task->message);
+ if (part) {
+ ct = g_mime_object_get_content_type (part);
+ g_object_unref (part);
+
+ if ((param_data = g_mime_content_type_get_parameter (ct, param_name)) == NULL) {
+ return FALSE;
}
- if (g_regex_match (re->regexp, param_data, 0, NULL) == TRUE) {
- return TRUE;
+ if (*param_pattern == '/') {
+ /* This is regexp, so compile and create g_regexp object */
+ if ((re = re_cache_check (param_pattern)) == NULL) {
+ re = parse_regexp (task->task_pool, param_pattern);
+ if (re == NULL) {
+ msg_warn ("rspamd_content_type_compare_param: cannot compile regexp for function");
+ return FALSE;
+ }
+ re_cache_add (param_pattern, re);
+ }
+ if (g_regex_match (re->regexp, param_data, 0, NULL) == TRUE) {
+ return TRUE;
+ }
}
- }
- else {
- /* Just do strcasecmp */
- if (g_ascii_strcasecmp (param_data, param_pattern) == 0) {
- return TRUE;
+ else {
+ /* Just do strcasecmp */
+ if (g_ascii_strcasecmp (param_data, param_pattern) == 0) {
+ return TRUE;
+ }
}
}
+
return FALSE;
}
@@ -740,6 +746,7 @@ rspamd_content_type_has_param (struct worker_task *task, GList *args)
char *param_name;
const char *param_data;
struct expression_argument *arg;
+ GMimeObject *part;
const GMimeContentType *ct;
if (args == NULL) {
@@ -748,9 +755,14 @@ rspamd_content_type_has_param (struct worker_task *task, GList *args)
}
arg = args->data;
param_name = arg->data;
- ct = g_mime_object_get_content_type (GMIME_OBJECT (g_mime_message_get_mime_part (task->message)));
- if ((param_data = g_mime_content_type_get_parameter (ct, param_name)) == NULL) {
- return FALSE;
+ part = g_mime_message_get_mime_part (task->message);
+ if (part) {
+ ct = g_mime_object_get_content_type (part);
+ g_object_unref (part);
+
+ if ((param_data = g_mime_content_type_get_parameter (ct, param_name)) == NULL) {
+ return FALSE;
+ }
}
return TRUE;
@@ -771,7 +783,8 @@ rspamd_content_type_is_subtype (struct worker_task *task, GList *args)
char *param_pattern;
struct rspamd_regexp *re;
struct expression_argument *arg;
- localContentType *ct;
+ GMimeObject *part;
+ const localContentType *ct;
if (args == NULL) {
msg_warn ("rspamd_content_type_compare_param: no parameters to function");
@@ -780,30 +793,34 @@ rspamd_content_type_is_subtype (struct worker_task *task, GList *args)
arg = args->data;
param_pattern = arg->data;
- ct = (localContentType *)g_mime_object_get_content_type (GMIME_OBJECT (g_mime_message_get_mime_part (task->message)));
+ part = g_mime_message_get_mime_part (task->message);
+ if (part) {
+ ct = (const localContentType *)g_mime_object_get_content_type (part);
+ g_object_unref (part);
- if (ct == NULL) {
- return FALSE;
- }
-
- if (*param_pattern == '/') {
- /* This is regexp, so compile and create g_regexp object */
- if ((re = re_cache_check (param_pattern)) == NULL) {
- re = parse_regexp (task->task_pool, param_pattern);
- if (re == NULL) {
- msg_warn ("rspamd_content_type_compare_param: cannot compile regexp for function");
- return FALSE;
- }
- re_cache_add (param_pattern, re);
+ if (ct == NULL) {
+ return FALSE;
}
- if (g_regex_match (re->regexp, ct->subtype, 0, NULL) == TRUE) {
- return TRUE;
+
+ if (*param_pattern == '/') {
+ /* This is regexp, so compile and create g_regexp object */
+ if ((re = re_cache_check (param_pattern)) == NULL) {
+ re = parse_regexp (task->task_pool, param_pattern);
+ if (re == NULL) {
+ msg_warn ("rspamd_content_type_compare_param: cannot compile regexp for function");
+ return FALSE;
+ }
+ re_cache_add (param_pattern, re);
+ }
+ if (g_regex_match (re->regexp, ct->subtype, 0, NULL) == TRUE) {
+ return TRUE;
+ }
}
- }
- else {
- /* Just do strcasecmp */
- if (g_ascii_strcasecmp (ct->subtype, param_pattern) == 0) {
- return TRUE;
+ else {
+ /* Just do strcasecmp */
+ if (g_ascii_strcasecmp (ct->subtype, param_pattern) == 0) {
+ return TRUE;
+ }
}
}
@@ -815,7 +832,8 @@ rspamd_content_type_is_type (struct worker_task *task, GList *args)
{
char *param_pattern;
struct rspamd_regexp *re;
- localContentType *ct;
+ GMimeObject *part;
+ const localContentType *ct;
struct expression_argument *arg;
if (args == NULL) {
@@ -825,30 +843,36 @@ rspamd_content_type_is_type (struct worker_task *task, GList *args)
arg = args->data;
param_pattern = arg->data;
- ct = (localContentType *)g_mime_object_get_content_type (GMIME_OBJECT (g_mime_message_get_mime_part (task->message)));
+ param_pattern = arg->data;
- if (ct == NULL) {
- return FALSE;
- }
-
- if (*param_pattern == '/') {
- /* This is regexp, so compile and create g_regexp object */
- if ((re = re_cache_check (param_pattern)) == NULL) {
- re = parse_regexp (task->task_pool, param_pattern);
- if (re == NULL) {
- msg_warn ("rspamd_content_type_compare_param: cannot compile regexp for function");
- return FALSE;
- }
- re_cache_add (param_pattern, re);
+ part = g_mime_message_get_mime_part (task->message);
+ if (part) {
+ ct = (const localContentType *)g_mime_object_get_content_type (part);
+ g_object_unref (part);
+
+ if (ct == NULL) {
+ return FALSE;
}
- if (g_regex_match (re->regexp, ct->type, 0, NULL) == TRUE) {
- return TRUE;
+
+ if (*param_pattern == '/') {
+ /* This is regexp, so compile and create g_regexp object */
+ if ((re = re_cache_check (param_pattern)) == NULL) {
+ re = parse_regexp (task->task_pool, param_pattern);
+ if (re == NULL) {
+ msg_warn ("rspamd_content_type_compare_param: cannot compile regexp for function");
+ return FALSE;
+ }
+ re_cache_add (param_pattern, re);
+ }
+ if (g_regex_match (re->regexp, ct->type, 0, NULL) == TRUE) {
+ return TRUE;
+ }
}
- }
- else {
- /* Just do strcasecmp */
- if (g_ascii_strcasecmp (ct->type, param_pattern) == 0) {
- return TRUE;
+ else {
+ /* Just do strcasecmp */
+ if (g_ascii_strcasecmp (ct->type, param_pattern) == 0) {
+ return TRUE;
+ }
}
}
diff --git a/src/mem_pool.c b/src/mem_pool.c
index ab96483f0..956a62422 100644
--- a/src/mem_pool.c
+++ b/src/mem_pool.c
@@ -23,7 +23,6 @@
*/
#include "config.h"
-
#include "mem_pool.h"
/* Sleep time for spin lock in nanoseconds */
diff --git a/src/worker.c b/src/worker.c
index cf716ee0d..02fcc8707 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -110,6 +110,9 @@ free_task (struct worker_task *task, gboolean is_soft)
g_byte_array_free (p->content, TRUE);
g_list_free_1 (part);
}
+ if (task->text_parts) {
+ g_list_free (task->text_parts);
+ }
memory_pool_delete (task->task_pool);
if (is_soft) {
/* Plan dispatcher shutdown */