summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2011-08-12 16:53:14 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2011-08-12 16:53:14 +0400
commit0b01a138daf4e83bd37750c7574b8c7dbef68f19 (patch)
treea9ee6975d837a86d27834e01faec9e062d50344e
parent45e3f01ca7f3487893b49ebea044ae73a1048123 (diff)
downloadrspamd-0b01a138daf4e83bd37750c7574b8c7dbef68f19.tar.gz
rspamd-0b01a138daf4e83bd37750c7574b8c7dbef68f19.zip
Fix critical bug with lua stack cleaning that caused heavy memory leaks.0.4.3
Update to 0.4.3.
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/client/rspamc.c2
-rw-r--r--src/lua/lua_cfg_file.c7
-rw-r--r--src/lua/lua_classifier.c7
-rw-r--r--src/lua/lua_common.c14
-rw-r--r--src/lua/lua_config.c6
-rw-r--r--src/plugins/regexp.c9
-rw-r--r--src/worker.c1
8 files changed, 35 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 924ee20d8..e703fd6da 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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}")
diff --git a/src/client/rspamc.c b/src/client/rspamc.c
index 8970d4d8f..e548993a4 100644
--- a/src/client/rspamc.c
+++ b/src/client/rspamc.c
@@ -23,7 +23,7 @@
*/
#include "config.h"
-#include "librspamdclient.h"
+#include "../../lib/librspamdclient.h"
#define PRINT_FUNC printf
diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c
index a7f023cb3..b63e6d985 100644
--- a/src/lua/lua_cfg_file.c
+++ b/src/lua/lua_cfg_file.c
@@ -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;
diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c
index 3eb66e188..32d4f88ed 100644
--- a/src/lua/lua_classifier.c
+++ b/src/lua/lua_classifier.c
@@ -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);
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 84f3bb659..67206b8ef 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -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;
}
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index d994d55aa..1c3017b6b 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -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));
}
}
diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c
index 008d85f39..b79997394 100644
--- a/src/plugins/regexp.c
+++ b/src/plugins/regexp.c
@@ -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;
}
diff --git a/src/worker.c b/src/worker.c
index 538218d14..fb67b119e 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -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