]> source.dussan.org Git - rspamd.git/commitdiff
* Fix 2 memory leaks
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 27 Mar 2009 10:47:00 +0000 (13:47 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 27 Mar 2009 10:47:00 +0000 (13:47 +0300)
* Fix uptime command output

src/controller.c
src/expressions.c
src/mem_pool.c
src/worker.c

index d82cc726e853cf9b8abae74a98cf69379bbd9aed..5a444b2757ad7fe2b1a6f2708d41f6dd998fe3bc 100644 (file)
@@ -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" : " ",
index b115eba723a7edb18789bdbeb8bb4077dd2c44ff..683e13dd8589d3bcdb1b0d36786e0b878ff455c5 100644 (file)
@@ -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;
+                       }
                }
        }
 
index ab96483f010a11f761973a4d7dd6d3d99631b7f1..956a624228f46511c2a329da2c55f653fb8eb9fd 100644 (file)
@@ -23,7 +23,6 @@
  */
 
 #include "config.h"
-
 #include "mem_pool.h"
 
 /* Sleep time for spin lock in nanoseconds */
index cf716ee0ddd417bbaa47db00a582fc7b76ae92d1..02fcc870773fa9543f7b879582c9682b747f2a8d 100644 (file)
@@ -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 */