From 5f45749d11981db96788bc496804eb29d61756fc Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 26 Feb 2016 17:26:33 +0000 Subject: Steal lua_text ownership to prevent gc --- src/lua/lua_tcp.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index 86a6bf723..93050eb2d 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -177,6 +177,7 @@ lua_tcp_write_helper (struct lua_tcp_cbdata *cbd) /* We know that niov is small enough for that */ cur_iov = alloca (niov * sizeof (struct iovec)); memcpy (cur_iov, cbd->iov, niov * sizeof (struct iovec)); + for (i = 0; i < cbd->iovlen && remain > 0; i++) { /* Find out the first iov required */ start = &cur_iov[i]; @@ -368,6 +369,12 @@ lua_tcp_arg_toiovec (lua_State *L, gint pos, rspamd_mempool_t *pool, if (t) { vec->iov_base = (void *)t->start; vec->iov_len = t->len; + + if (t->own) { + /* Steal ownership */ + t->own = FALSE; + rspamd_mempool_add_destructor (pool, g_free, (void *)t->start); + } } else { return FALSE; -- cgit v1.2.3