aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-14 11:47:36 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-14 15:15:19 +0100
commit7406e60b74327df055f3bacfc478bd5cb68fd6c9 (patch)
tree9589f52da4b7e19f2eb0997674503763107619af /src/lua
parent700949bd941aeec41060163e36509061791c502f (diff)
downloadrspamd-7406e60b74327df055f3bacfc478bd5cb68fd6c9.tar.gz
rspamd-7406e60b74327df055f3bacfc478bd5cb68fd6c9.zip
[Fix] Cleanup maps data on shutdown
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_map.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c
index 2d2a098d2..d5914706c 100644
--- a/src/lua/lua_map.c
+++ b/src/lua/lua_map.c
@@ -156,6 +156,7 @@ lua_config_add_radix_map (lua_State *L)
if ((m = rspamd_map_add (cfg, map_line, description,
rspamd_radix_read,
rspamd_radix_fin,
+ rspamd_radix_dtor,
(void **)&map->data.radix)) == NULL) {
msg_warn_config ("invalid radix map %s", map_line);
lua_pushnil (L);
@@ -211,6 +212,7 @@ lua_config_radix_from_config (lua_State *L)
if ((m = rspamd_map_add_from_ucl (cfg, fake_obj, "static radix map",
rspamd_radix_read,
rspamd_radix_fin,
+ rspamd_radix_dtor,
(void **)&map->data.radix)) == NULL) {
msg_err_config ("invalid radix map static");
lua_pushnil (L);
@@ -270,6 +272,7 @@ lua_config_radix_from_ucl (lua_State *L)
if ((m = rspamd_map_add_from_ucl (cfg, fake_obj, "static radix map",
rspamd_radix_read,
rspamd_radix_fin,
+ rspamd_radix_dtor,
(void **)&map->data.radix)) == NULL) {
msg_err_config ("invalid radix map static");
lua_pushnil (L);
@@ -311,6 +314,7 @@ lua_config_add_hash_map (lua_State *L)
if ((m = rspamd_map_add (cfg, map_line, description,
rspamd_kv_list_read,
rspamd_kv_list_fin,
+ rspamd_kv_list_dtor,
(void **)&map->data.hash)) == NULL) {
msg_warn_config ("invalid set map %s", map_line);
lua_pushnil (L);
@@ -349,6 +353,7 @@ lua_config_add_kv_map (lua_State *L)
if ((m = rspamd_map_add (cfg, map_line, description,
rspamd_kv_list_read,
rspamd_kv_list_fin,
+ rspamd_kv_list_dtor,
(void **)&map->data.hash)) == NULL) {
msg_warn_config ("invalid hash map %s", map_line);
lua_pushnil (L);
@@ -441,6 +446,23 @@ lua_map_fin (struct map_cb_data *data)
cbdata->data = rspamd_fstring_assign (cbdata->data, "", 0);
}
+static void
+lua_map_dtor (struct map_cb_data *data)
+{
+ struct lua_map_callback_data *cbdata;
+
+ if (data->cur_data) {
+ cbdata = (struct lua_map_callback_data *)data->cur_data;
+ if (cbdata->ref != -1) {
+ luaL_unref (cbdata->L, LUA_REGISTRYINDEX, cbdata->ref);
+ }
+
+ if (cbdata->data) {
+ rspamd_fstring_free (cbdata->data);
+ }
+ }
+}
+
gint
lua_config_add_map (lua_State *L)
{
@@ -488,7 +510,9 @@ lua_config_add_map (lua_State *L)
cbdata->ref = cbidx;
if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
- lua_map_read, lua_map_fin,
+ lua_map_read,
+ lua_map_fin,
+ lua_map_dtor,
(void **)&map->data.cbdata)) == NULL) {
if (cbidx != -1) {
@@ -513,6 +537,7 @@ lua_config_add_map (lua_State *L)
if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
rspamd_kv_list_read,
rspamd_kv_list_fin,
+ rspamd_kv_list_dtor,
(void **)&map->data.hash)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);
@@ -529,6 +554,7 @@ lua_config_add_map (lua_State *L)
if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
rspamd_kv_list_read,
rspamd_kv_list_fin,
+ rspamd_kv_list_dtor,
(void **)&map->data.hash)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);
@@ -545,6 +571,7 @@ lua_config_add_map (lua_State *L)
if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
rspamd_radix_read,
rspamd_radix_fin,
+ rspamd_radix_dtor,
(void **)&map->data.radix)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);
@@ -561,6 +588,7 @@ lua_config_add_map (lua_State *L)
if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
rspamd_regexp_list_read_single,
rspamd_regexp_list_fin,
+ rspamd_regexp_list_dtor,
(void **) &map->data.re_map)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);
@@ -577,6 +605,7 @@ lua_config_add_map (lua_State *L)
if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
rspamd_regexp_list_read_multiple,
rspamd_regexp_list_fin,
+ rspamd_regexp_list_dtor,
(void **) &map->data.re_map)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);
@@ -593,6 +622,7 @@ lua_config_add_map (lua_State *L)
if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
rspamd_glob_list_read_single,
rspamd_regexp_list_fin,
+ rspamd_regexp_list_dtor,
(void **) &map->data.re_map)) == NULL) {
lua_pushnil (L);
ucl_object_unref (map_obj);