diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-05-20 12:03:46 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-05-20 12:03:46 +0100 |
commit | 2dafca29378d0bd77d972f87bf2c8999e8fec14f (patch) | |
tree | ff0dbf619ffc8d82a4d1350212bfb66d5a69a410 /src/lua/lua_task.c | |
parent | 92496d02007139d676a9ca4a35f288b368658be4 (diff) | |
download | rspamd-2dafca29378d0bd77d972f87bf2c8999e8fec14f.tar.gz rspamd-2dafca29378d0bd77d972f87bf2c8999e8fec14f.zip |
Allow owning lua_text.
Diffstat (limited to 'src/lua/lua_task.c')
-rw-r--r-- | src/lua/lua_task.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index d8f14a243..d23f9143b 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -529,12 +529,14 @@ static const struct luaL_reg imagelib_m[] = { LUA_FUNCTION_DEF (text, len); LUA_FUNCTION_DEF (text, str); LUA_FUNCTION_DEF (text, ptr); +LUA_FUNCTION_DEF (text, gc); static const struct luaL_reg textlib_m[] = { LUA_INTERFACE_DEF (text, len), LUA_INTERFACE_DEF (text, str), LUA_INTERFACE_DEF (text, ptr), {"__tostring", lua_text_str}, + {"__gc", lua_text_gc}, {NULL, NULL} }; @@ -836,6 +838,7 @@ lua_task_get_content (lua_State * L) rspamd_lua_setclass (L, "rspamd{text}", -1); t->len = task->msg.len; t->start = task->msg.start; + t->own = FALSE; return 1; } @@ -1040,6 +1043,7 @@ lua_task_get_raw_headers (lua_State *L) rspamd_lua_setclass (L, "rspamd{text}", -1); t->start = task->raw_headers_str; t->len = strlen (t->start); + t->own = FALSE; } else { lua_pushnil (L); @@ -2022,6 +2026,18 @@ lua_text_ptr (lua_State *L) return 1; } +static gint +lua_text_gc (lua_State *L) +{ + struct rspamd_lua_text *t = lua_check_text (L, 1); + + if (t != NULL && t->own) { + g_free ((gpointer)t->start); + } + + return 0; +} + /* Init part */ static gint |