]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Steal lua_text ownership to prevent gc
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 26 Feb 2016 17:26:33 +0000 (17:26 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 26 Feb 2016 17:26:33 +0000 (17:26 +0000)
src/lua/lua_tcp.c

index 86a6bf72367d42ac8d68b350d96bc88db333246a..93050eb2d2961701b80672c79e55667aad5a31f1 100644 (file)
@@ -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;