BUG/MINOR: hlua: fix invalid use of lua_pop on error paths

Multiple error paths made invalid use of lua_pop():

When the stack is emptied using lua_settop(0), lua_pop() (which is
implemented as a lua_settop() macro) should not be used right after,
because it could lead to invalid reads since the stack is already empty.

Unfortunately, some remnants from initial lua stack implementation kept
doing so, resulting in haproxy crashs on some lua runtime errors paths
from time to time (ie: ERRRUN, ERRMEM).

Moreover, the extra lua_pop() instruction, even if it was safe, is totally
pointless in such case.

Removing such unsafe lua_pop() statements when we know that the stack is
already empty.

This must be backported in every stable versions.

(cherry picked from commit 12cf8d4db7f0d239caf7ff3d94b62da2d953495c)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 3e81aed0ad8373435d656266ea6a46dc49c15977)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 2872047eb879de5c87324fe7d717468d592502d0)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 931aaa31e8bd2c2b085cdf3c8e9c6aac61ff4941)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/hlua.c b/src/hlua.c
index 2716f84..ce76a32 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -1434,7 +1434,6 @@
 		}
 		msg = lua_tostring(lua->T, -1);
 		lua_settop(lua->T, 0); /* Empty the stack. */
-		lua_pop(lua->T, 1);
 		trace = hlua_traceback(lua->T, ", ");
 		if (msg)
 			lua_pushfstring(lua->T, "[state-id %d] runtime error: %s from %s", lua->state_id, msg, trace);
@@ -1457,7 +1456,6 @@
 		}
 		msg = lua_tostring(lua->T, -1);
 		lua_settop(lua->T, 0); /* Empty the stack. */
-		lua_pop(lua->T, 1);
 		if (msg)
 			lua_pushfstring(lua->T, "[state-id %d] message handler error: %s", lua->state_id, msg);
 		else
@@ -8676,7 +8674,6 @@
 				kind = "runtime error";
 			msg = lua_tostring(L, -1);
 			lua_settop(L, 0); /* Empty the stack. */
-			lua_pop(L, 1);
 			trace = hlua_traceback(L, ", ");
 			if (msg)
 				ha_alert("Lua init: %s: '%s' from %s\n", kind, msg, trace);
@@ -8697,8 +8694,7 @@
 		case LUA_ERRMEM:
 			if (!kind)
 				kind = "out of memory error";
-			lua_settop(L, 0);
-			lua_pop(L, 1);
+			lua_settop(L, 0); /* Empty the stack. */
 			trace = hlua_traceback(L, ", ");
 			ha_alert("Lua init: %s: %s\n", kind, trace);
 			return_status = 0;