]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: lua-thread: close all states on deinit
authorWilly Tarreau <w@1wt.eu>
Fri, 4 Dec 2020 10:48:12 +0000 (11:48 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 4 Dec 2020 11:00:11 +0000 (12:00 +0100)
It seems to me that lua_close() must be called on all states at deinit
time, not just the first two ones. This is likely a remnant of commit
59f11be43 ("MEDIUM: lua-thread: Add the lua-load-per-thread directive").
There should likely be some memory leak reports when using Lua without
this fix, though none were observed for now.

No backport is needed as this was merged into 2.4-dev.

src/hlua.c

index 66d0b7bbcd6c6915aacc5eeb07dc7babf026a56d..fbccaaaaaf418832ab284bda8d26fba690d1343a 100644 (file)
@@ -191,7 +191,7 @@ lua_State *hlua_init_state(int thread_id);
 /* The main Lua execution context. The 0 index is the
  * common state shared by all threads.
  */
-lua_State *hlua_states[MAX_THREADS + 1];
+static lua_State *hlua_states[MAX_THREADS + 1];
 
 /* This is the memory pool containing struct lua for applets
  * (including cli).
@@ -9287,8 +9287,12 @@ void hlua_init(void) {
 
 static void hlua_deinit()
 {
-       lua_close(hlua_states[0]);
-       lua_close(hlua_states[1]);
+       int thr;
+
+       for (thr = 0; thr < MAX_THREADS+1; thr++) {
+               if (hlua_states[thr])
+                       lua_close(hlua_states[thr]);
+       }
 }
 
 REGISTER_POST_DEINIT(hlua_deinit);