aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_task.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-08-07 12:55:47 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-08-07 12:55:47 +0100
commit66ffcdfa880daeb3b50c7ef3bcb5511abb6d92f6 (patch)
tree682d91608d2f1335b9acd188d63261542b0c98cb /src/lua/lua_task.c
parent6ac122670a3dc4102e4993db2d668169183a7f32 (diff)
downloadrspamd-66ffcdfa880daeb3b50c7ef3bcb5511abb6d92f6.tar.gz
rspamd-66ffcdfa880daeb3b50c7ef3bcb5511abb6d92f6.zip
[Minor] Various fixes to lua_task_load_from_string method
Diffstat (limited to 'src/lua/lua_task.c')
-rw-r--r--src/lua/lua_task.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index e11a982cd..83adc99a2 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -1244,6 +1244,16 @@ lua_task_unmap_dtor (gpointer p)
}
}
+static void
+lua_task_free_dtor (gpointer p)
+{
+ struct rspamd_task *task = (struct rspamd_task *)p;
+
+ if (task->msg.begin) {
+ g_free ((gpointer)task->msg.begin);
+ }
+}
+
static gint
lua_task_load_from_file (lua_State * L)
{
@@ -1306,10 +1316,11 @@ static gint
lua_task_load_from_string (lua_State * L)
{
struct rspamd_task *task = NULL, **ptask;
- const gchar *str_message = luaL_checkstring (L, 1), *err = NULL;
- gsize message_len = lua_strlen (L, 1);
+ const gchar *str_message;
+ gsize message_len;
struct rspamd_config *cfg = NULL;
- gboolean res = FALSE;
+
+ str_message = luaL_checklstring (L, 1, &message_len);
if (str_message) {
@@ -1323,31 +1334,19 @@ lua_task_load_from_string (lua_State * L)
}
task = rspamd_task_new (NULL, cfg, NULL, NULL);
- task->msg.begin = str_message;
+ task->msg.begin = g_strdup (str_message);
task->msg.len = message_len;
- rspamd_mempool_add_destructor (task->task_pool,
- lua_task_unmap_dtor, task);
- res = TRUE;
+ rspamd_mempool_add_destructor (task->task_pool, lua_task_free_dtor, task);
}
else {
return luaL_error (L, "invalid arguments");
}
- lua_pushboolean (L, res);
+ lua_pushboolean (L, true);
- if (res) {
- ptask = lua_newuserdata (L, sizeof (*ptask));
- *ptask = task;
- rspamd_lua_setclass (L, "rspamd{task}", -1);
- }
- else {
- if (err) {
- lua_pushstring (L, err);
- }
- else {
- lua_pushnil (L);
- }
- }
+ ptask = lua_newuserdata (L, sizeof (*ptask));
+ *ptask = task;
+ rspamd_lua_setclass (L, "rspamd{task}", -1);
return 2;
}