diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2012-08-22 21:41:48 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2012-08-22 21:41:48 +0400 |
commit | b90267a71cc8cdc8b38675322ef9fa7a9cb5468c (patch) | |
tree | 3bff8af523d19ec9cff93134b067fc404795000d /src/lua/lua_classifier.c | |
parent | ed224e6a3530f54b5993e39066a8397d54e9517e (diff) | |
download | rspamd-b90267a71cc8cdc8b38675322ef9fa7a9cb5468c.tar.gz rspamd-b90267a71cc8cdc8b38675322ef9fa7a9cb5468c.zip |
* Rework thread pools locking logic to avoid global lua mutex usage.
Fixed several memory leaks with modern glib.
Fixed memory leak in dkim code.
Fixed a problem with static global variables in shared libraries.
Diffstat (limited to 'src/lua/lua_classifier.c')
-rw-r--r-- | src/lua/lua_classifier.c | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c index e929c6b50..4962a0e2b 100644 --- a/src/lua/lua_classifier.c +++ b/src/lua/lua_classifier.c @@ -117,27 +117,24 @@ call_classifier_pre_callback (struct classifier_config *ccf, struct worker_task /* Return list of statfiles that should be checked for this message */ GList * call_classifier_pre_callbacks (struct classifier_config *ccf, struct worker_task *task, - gboolean is_learn, gboolean is_spam) + gboolean is_learn, gboolean is_spam, lua_State *L) { GList *res = NULL, *cur; 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) { cd = cur->data; - lua_getglobal (cd->L, cd->name); + lua_getglobal (L, cd->name); - res = g_list_concat (res, call_classifier_pre_callback (ccf, task, cd->L, is_learn, is_spam)); + res = g_list_concat (res, call_classifier_pre_callback (ccf, task, L, is_learn, is_spam)); cur = g_list_next (cur); } - - g_mutex_lock (lua_mtx); + if (res == NULL) { - L = task->cfg->lua_state; /* Check function from global table 'classifiers' */ lua_getglobal (L, "classifiers"); if (lua_istable (L, -1)) { @@ -151,14 +148,13 @@ call_classifier_pre_callbacks (struct classifier_config *ccf, struct worker_task } lua_pop (L, 1); } - g_mutex_unlock (lua_mtx); return res; } /* Return result mark for statfile */ double -call_classifier_post_callbacks (struct classifier_config *ccf, struct worker_task *task, double in) +call_classifier_post_callbacks (struct classifier_config *ccf, struct worker_task *task, double in, lua_State *L) { struct classifier_callback_data *cd; struct classifier_config **pccf; @@ -166,36 +162,34 @@ call_classifier_post_callbacks (struct classifier_config *ccf, struct worker_tas double out = in; GList *cur; - g_mutex_lock (lua_mtx); /* Go throught all callbacks and call them, appending results to list */ cur = g_list_first (ccf->pre_callbacks); while (cur) { cd = cur->data; - lua_getglobal (cd->L, cd->name); + lua_getglobal (L, cd->name); - pccf = lua_newuserdata (cd->L, sizeof (struct classifier_config *)); - lua_setclass (cd->L, "rspamd{classifier}", -1); + pccf = lua_newuserdata (L, sizeof (struct classifier_config *)); + lua_setclass (L, "rspamd{classifier}", -1); *pccf = ccf; - ptask = lua_newuserdata (cd->L, sizeof (struct worker_task *)); - lua_setclass (cd->L, "rspamd{task}", -1); + ptask = lua_newuserdata (L, sizeof (struct worker_task *)); + lua_setclass (L, "rspamd{task}", -1); *ptask = task; - lua_pushnumber (cd->L, out); + lua_pushnumber (L, out); - if (lua_pcall (cd->L, 3, 1, 0) != 0) { - msg_warn ("error running function %s: %s", cd->name, lua_tostring (cd->L, -1)); + if (lua_pcall (L, 3, 1, 0) != 0) { + msg_warn ("error running function %s: %s", cd->name, lua_tostring (L, -1)); } else { - if (lua_isnumber (cd->L, 1)) { - out = lua_tonumber (cd->L, 1); + if (lua_isnumber (L, 1)) { + out = lua_tonumber (L, 1); } - lua_pop (cd->L, 1); + lua_pop (L, 1); } cur = g_list_next (cur); } - g_mutex_unlock (lua_mtx); return out; |