]> source.dussan.org Git - rspamd.git/commitdiff
Fix critical bug with lua stack cleaning that caused heavy memory leaks. 0.4.3
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 12 Aug 2011 12:53:14 +0000 (16:53 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 12 Aug 2011 12:53:14 +0000 (16:53 +0400)
Update to 0.4.3.

CMakeLists.txt
src/client/rspamc.c
src/lua/lua_cfg_file.c
src/lua/lua_classifier.c
src/lua/lua_common.c
src/lua/lua_config.c
src/plugins/regexp.c
src/worker.c

index 924ee20d873a8abb28f25c34894627225c416108..e703fd6da1e10bf313fcc9bbc1e24dd1c33938a2 100644 (file)
@@ -7,7 +7,7 @@ PROJECT(rspamd C)
 
 SET(RSPAMD_VERSION_MAJOR 0)
 SET(RSPAMD_VERSION_MINOR 4)
-SET(RSPAMD_VERSION_PATCH 2)
+SET(RSPAMD_VERSION_PATCH 3)
 
 
 SET(RSPAMD_VERSION         "${RSPAMD_VERSION_MAJOR}.${RSPAMD_VERSION_MINOR}.${RSPAMD_VERSION_PATCH}")
index 8970d4d8f97907a3f58b552e9c5d6b4e9aebc437..e548993a47b732a403f3fcb62d5b34643f0160bd 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 #include "config.h"
-#include "librspamdclient.h"
+#include "../../lib/librspamdclient.h"
 
 #define PRINT_FUNC printf
 
index a7f023cb3d9622dd14e37a000ff33ded39c33120..b63e6d985578e729dde0b4368a5b31fababd3654 100644 (file)
@@ -396,32 +396,39 @@ lua_handle_param (struct worker_task *task, gchar *mname, gchar *optname, enum l
                                switch (expected_type) {
                                        case LUA_VAR_NUM:
                                                if (!lua_isnumber (L, -1)) {
+                                                       lua_pop (L, 1);
                                                        *res = NULL;
                                                        return FALSE;
                                                }
                                                num_res = lua_tonumber (L, -1);
                                                *res = memory_pool_alloc (task->task_pool, sizeof (double));
                                                **(double **)res = num_res;
+                                               lua_pop (L, 1);
                                                return TRUE;
                                        case LUA_VAR_BOOLEAN:
                                                if (!lua_isboolean (L, -1)) {
+                                                       lua_pop (L, 1);
                                                        *res = NULL;
                                                        return FALSE;
                                                }
                                                bool_res = lua_toboolean (L, -1);
                                                *res = memory_pool_alloc (task->task_pool, sizeof (gboolean));
                                                **(gboolean **)res = bool_res;
+                                               lua_pop (L, 1);
                                                return TRUE;
                                        case LUA_VAR_STRING:
                                                if (!lua_isstring (L, -1)) {
+                                                       lua_pop (L, 1);
                                                        *res = NULL;
                                                        return FALSE;
                                                }
                                                str_res = memory_pool_strdup (task->task_pool, lua_tostring (L, -1));
                                                *res = str_res;
+                                               lua_pop (L, 1);
                                                return TRUE;
                                        case LUA_VAR_FUNCTION:
                                        case LUA_VAR_UNKNOWN:
+                                               lua_pop (L, 1);
                                                msg_err ("cannot expect function or unknown types");
                                                *res = NULL;
                                                return FALSE;
index 3eb66e1880743ff2fd59fde20afe1212bb52f65c..32d4f88ed35d3f92e58bcd5a9e79cdf42cc7cd66 100644 (file)
@@ -108,8 +108,8 @@ call_classifier_pre_callback (struct classifier_config *ccf, struct worker_task
                                }
                                lua_pop (L, 1);
                        }
-                       lua_pop (L, 1);
                }
+               lua_pop (L, 1);
        }
 
        return res;
@@ -124,7 +124,6 @@ call_classifier_pre_callbacks (struct classifier_config *ccf, struct worker_task
        struct classifier_callback_data *cd;
        lua_State                       *L;
 
-
        /* Go throught all callbacks and call them, appending results to list */
        cur = g_list_first (ccf->pre_callbacks);
        while (cur) {
@@ -147,9 +146,10 @@ call_classifier_pre_callbacks (struct classifier_config *ccf, struct worker_task
                        if (lua_isfunction (L, -1)) {
                                res = call_classifier_pre_callback (ccf, task, L, is_learn, is_spam);
                        }
+                       lua_pop (L, 1);
                }
+               lua_pop (L, 1);
        }
-
        return res;
 }
 
@@ -186,6 +186,7 @@ call_classifier_post_callbacks (struct classifier_config *ccf, struct worker_tas
                        if (lua_isnumber (cd->L, 1)) {
                                out = lua_tonumber (cd->L, 1);
                        }
+                       lua_pop (cd->L, 1);
                }
 
                cur = g_list_next (cur);
index 84f3bb6594609d1a30844c8ff51e5819edda6887..67206b8ef3da10e3699752ca5223594f6371539f 100644 (file)
@@ -371,7 +371,7 @@ lua_call_expression_func (const gchar *module, const gchar *function,
        struct worker_task            **ptask;
        GList                          *cur;
        struct expression_argument     *arg;
-       int                             nargs = 1;
+       int                             nargs = 1, pop = 0;
 
        /* Call specified function and expect result of given expected_type */
        /* First check function in config table */
@@ -381,19 +381,25 @@ lua_call_expression_func (const gchar *module, const gchar *function,
                lua_gettable (L, -2);
                if (lua_isnil (L, -1)) {
                        /* Try to get global variable */
+                       lua_pop (L, 1);
                        lua_getglobal (L, function);
                }
                else {
                        /* Call local function in table */
                        lua_pushstring (L, function);
                        lua_gettable (L, -2);
+                       pop += 2;
                }
        }
        else {
                /* Try to get global variable */
+               lua_pop (L, 1);
                lua_getglobal (L, function);
        }
        if (lua_isnil (L, -1)) {
+               if (pop > 0) {
+                       lua_pop (L, pop);
+               }
                msg_err ("function with name %s is not defined", function);
                return FALSE;
        }
@@ -427,13 +433,16 @@ lua_call_expression_func (const gchar *module, const gchar *function,
                msg_info ("call to %s failed: %s", function, lua_tostring (L, -1));
                return FALSE;
        }
+       pop ++;
 
        if (!lua_isboolean (L, -1)) {
+               lua_pop (L, pop);
                msg_info ("function %s must return a boolean", function);
                return FALSE;
        }
        *res = lua_toboolean (L, -1);
-       
+       lua_pop (L, pop);
+
        return TRUE;
 }
 
@@ -518,6 +527,7 @@ lua_normalizer_func (struct config_file *cfg, long double score, void *params)
                msg_info ("function %s must return a number", p->data);
        }
        res = lua_tonumber (L, -1);
+       lua_pop (L, 1);
 
     return res;
 }
index d994d55aafa46ec5af7ca187fca9eda0418c145e..1c3017b6bce4fec9e8b4bd563517dd43b881be4d 100644 (file)
@@ -319,6 +319,7 @@ lua_config_function_callback (struct worker_task *task, GList *args, void *user_
                if (lua_isboolean (cd->L, 1)) {
                        res = lua_toboolean (cd->L, 1);
                }
+               lua_pop (cd->L, 1);
        }
 
        return res;
@@ -410,7 +411,7 @@ lua_call_post_filters (struct worker_task *task)
                lua_setclass (cd->L, "rspamd{task}", -1);
                *ptask = task;
 
-               if (lua_pcall (cd->L, 1, 1, 0) != 0) {
+               if (lua_pcall (cd->L, 1, 0, 0) != 0) {
                        msg_warn ("error running function %s: %s", cd->name, lua_tostring (cd->L, -1));
                }
                cur = g_list_next (cur);
@@ -535,13 +536,12 @@ lua_metric_symbol_callback (struct worker_task *task, gpointer ud)
 {
        struct lua_callback_data       *cd = ud;
        struct worker_task            **ptask;
-
        lua_getglobal (cd->L, cd->name);
        ptask = lua_newuserdata (cd->L, sizeof (struct worker_task *));
        lua_setclass (cd->L, "rspamd{task}", -1);
        *ptask = task;
 
-       if (lua_pcall (cd->L, 1, 1, 0) != 0) {
+       if (lua_pcall (cd->L, 1, 0, 0) != 0) {
                msg_warn ("error running function %s: %s", cd->name, lua_tostring (cd->L, -1));
        }
 }
index 008d85f3913371ef3295a09811b26316a5b38345..b7999739420173ddab84a40e46dd83df7f0da8a6 100644 (file)
@@ -956,6 +956,7 @@ maybe_call_lua_function (const gchar *name, struct worker_task *task)
 {
        lua_State                      *L = task->cfg->lua_state;
        struct worker_task            **ptask;
+       gboolean                        res;
 
        lua_getglobal (L, name);
        if (lua_isfunction (L, -1)) {
@@ -967,9 +968,13 @@ maybe_call_lua_function (const gchar *name, struct worker_task *task)
                        msg_info ("call to %s failed: %s", (gchar *)name, lua_tostring (L, -1));
                        return FALSE;
                }
-               return lua_toboolean (L, -1);
+               res = lua_toboolean (L, -1);
+               lua_pop (L, 1);
+               return res;
+       }
+       else {
+               lua_pop (L, 1);
        }
-
        return FALSE;
 }
 
index 538218d14b1ae82cac725223c14b751ac1f4d5a9..fb67b119e5ed5af26d2baf2055b9e9915fbf71ff 100644 (file)
@@ -500,7 +500,6 @@ accept_socket (gint fd, short what, void *arg)
                new_task->rcpt = g_list_reverse (new_task->rcpt);
        }
 #endif
-
 }
 
 #ifndef BUILD_STATIC