Tarantool development patches archive
 help / color / mirror / Atom feed
From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: Alexander Turenko <alexander.turenko@tarantool.org>,
	tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH] Fix premature cdata collecting in luaT_pusherror()
Date: Fri,  7 Dec 2018 18:16:28 +0300	[thread overview]
Message-ID: <480868ff8f304ead2fd03e317902a1e8d41c6248.1544195642.git.alexander.turenko@tarantool.org> (raw)

This is follow up of 28c7e667aee9be8c3288597bcc179d9b4e7b4940 to fix
luaT_pusherror() itself, not only luaT_error().

Fixes #1955 (again).
---

https://github.com/tarantool/tarantool/issues/1955
https://github.com/tarantool/tarantool/tree/Totktonada/gh-1955-fix-luaT_pusherror

 src/lua/error.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/lua/error.c b/src/lua/error.c
index 71345927d..fca87f9d6 100644
--- a/src/lua/error.c
+++ b/src/lua/error.c
@@ -75,12 +75,20 @@ luaL_error_gc(struct lua_State *L)
 void
 luaT_pusherror(struct lua_State *L, struct error *e)
 {
+	/*
+	 * gh-1955 luaT_pusherror allocates Lua objects, thus it
+	 * may trigger GC. GC may invoke finalizers which are
+	 * arbitrary Lua code, potentially invalidating last error
+	 * object, hence error_ref below.
+	 *
+	 * It also important to reference the error first and only
+	 * then set the finalizer.
+	 */
+	error_ref(e);
 	assert(CTID_CONST_STRUCT_ERROR_REF != 0);
 	struct error **ptr = (struct error **)
 		luaL_pushcdata(L, CTID_CONST_STRUCT_ERROR_REF);
 	*ptr = e;
-	/* The order is important - first reference the error, then set gc */
-	error_ref(e);
 	lua_pushcfunction(L, luaL_error_gc);
 	luaL_setcdatagc(L, -2);
 }
@@ -90,15 +98,7 @@ luaT_error(lua_State *L)
 {
 	struct error *e = diag_last_error(&fiber()->diag);
 	assert(e != NULL);
-	/*
-	 * gh-1955 luaT_pusherror allocates Lua objects, thus it may trigger
-	 * GC. GC may invoke finalizers which are arbitrary Lua code,
-	 * potentially invalidating last error object, hence error_ref
-	 * below.
-	 */
-	error_ref(e);
 	luaT_pusherror(L, e);
-	error_unref(e);
 	lua_error(L);
 	unreachable();
 	return 0;
-- 
2.19.2

             reply	other threads:[~2018-12-07 15:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-07 15:16 Alexander Turenko [this message]
2018-12-07 17:32 ` [tarantool-patches] " Konstantin Osipov
2018-12-07 18:15   ` [tarantool-patches] " Alexander Turenko
2018-12-07 20:42     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-07 22:24       ` Konstantin Osipov
2018-12-09 10:35 ` [tarantool-patches] " Vladimir Davydov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=480868ff8f304ead2fd03e317902a1e8d41c6248.1544195642.git.alexander.turenko@tarantool.org \
    --to=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH] Fix premature cdata collecting in luaT_pusherror()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox