From 65f61fa6047a09347972af1214f45149be311fb6 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Tue, 24 Feb 2015 23:36:59 +0300 Subject: Fix segfault in LG_lane_new STACK_END macro was used to check stack size of child Lua state _after_ its thread was launched. That could lead to the check failing as the child thread started manipulating the stack. The macro then called lua_error on the child state from the parent thread, causing a segfault as Lua C API is not thread-safe. The fix is to place STACK_END statements before THREAD_CREATE statement. --- src/lanes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lanes.c b/src/lanes.c index 9b95469..8852687 100644 --- a/src/lanes.c +++ b/src/lanes.c @@ -2419,13 +2419,13 @@ LUAG_FUNC( lane_new) lua_sethook( L2, cancel_hook, LUA_MASKCOUNT, cancelstep_idx); } + STACK_END( L, 1); + STACK_END( L2, 1 + nargs); + DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: launching thread\n" INDENT_END)); THREAD_CREATE( &s->thread, lane_main, s, priority); DEBUGSPEW_CODE( -- U->debugspew_indent_depth); - - STACK_END( L, 1); - STACK_END( L2, 1 + nargs); return 1; } -- cgit v1.2.3-55-g6feb