diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-09-12 14:23:15 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-09-12 14:23:15 +0100 |
commit | 1a8db1b73104eb6e120becd4ee0c56e59de717b4 (patch) | |
tree | 7bca7306668e66d35eff8dc8b943ec895d0bf3eb | |
parent | 219e642ffd46aac0ae905ef682df16eab9b6e93b (diff) | |
download | rspamd-1a8db1b73104eb6e120becd4ee0c56e59de717b4.tar.gz rspamd-1a8db1b73104eb6e120becd4ee0c56e59de717b4.zip |
[Fix] Fix another cleanup race condition
-rw-r--r-- | src/lua/lua_http.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 2eb49d281..f028e63d2 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -55,6 +55,7 @@ static const struct luaL_reg httplib_m[] = { #define RSPAMD_LUA_HTTP_FLAG_TEXT (1 << 0) #define RSPAMD_LUA_HTTP_FLAG_NOVERIFY (1 << 1) +#define RSPAMD_LUA_HTTP_FLAG_RESOLVED (1 << 2) struct lua_http_cbdata { struct rspamd_http_connection *conn; @@ -144,9 +145,14 @@ lua_http_fin (gpointer arg) static void lua_http_maybe_free (struct lua_http_cbdata *cbd) { - if (cbd->session) { + if (cbd->session && cbd->w) { + /* We still need to clear watcher */ rspamd_session_watcher_pop (cbd->session, cbd->w); - rspamd_session_remove_event (cbd->session, lua_http_fin, cbd); + + if (cbd->flags & RSPAMD_LUA_HTTP_FLAG_RESOLVED) { + /* Event is added merely for resolved events */ + rspamd_session_remove_event (cbd->session, lua_http_fin, cbd); + } } else { lua_http_fin (cbd); @@ -400,6 +406,14 @@ lua_http_make_connection (struct lua_http_cbdata *cbd) /* Message is now owned by a connection object */ cbd->msg = NULL; + if (cbd->session) { + rspamd_session_add_event (cbd->session, + (event_finalizer_t)lua_http_fin, + cbd, + g_quark_from_static_string ("lua http")); + cbd->flags |= RSPAMD_LUA_HTTP_FLAG_RESOLVED; + } + return TRUE; } @@ -849,12 +863,9 @@ lua_http_request (lua_State *L) if (session) { cbd->session = session; - rspamd_session_add_event (session, - (event_finalizer_t)lua_http_fin, - cbd, - g_quark_from_static_string ("lua http")); - cbd->w = rspamd_session_get_watcher (session); - rspamd_session_watcher_push_specific (session, cbd->w); + + cbd->w = rspamd_session_get_watcher (cbd->session); + rspamd_session_watcher_push_specific (cbd->session, cbd->w); } if (rspamd_parse_inet_address (&cbd->addr, msg->host->str, msg->host->len)) { |