From d7e5682c32a1b38108d1c109f22369714e8489f2 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 27 Jan 2022 18:04:24 +0200 Subject: [PATCH 39/39] gcc-12: Fix "use after free" warning in tolua See osdn #43711 Signed-off-by: Marko Lindqvist --- dependencies/tolua-5.2/freeciv_tolua.patch | 22 ++++++++++++++------ dependencies/tolua-5.2/src/lib/tolua_event.c | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/dependencies/tolua-5.2/freeciv_tolua.patch b/dependencies/tolua-5.2/freeciv_tolua.patch index 351166d21f..66479afa0e 100644 --- a/dependencies/tolua-5.2/freeciv_tolua.patch +++ b/dependencies/tolua-5.2/freeciv_tolua.patch @@ -1,6 +1,6 @@ diff -Nurd tolua-5.2/src/bin/tolua.c tolua-5.2/src/bin/tolua.c ---- tolua-5.2/src/bin/tolua.c 2016-01-06 01:19:24.984940138 +0200 -+++ tolua-5.2/src/bin/tolua.c 2016-01-06 01:22:44.160507862 +0200 +--- tolua-5.2/src/bin/tolua.c 2022-01-27 13:47:57.409903222 +0200 ++++ tolua-5.2/src/bin/tolua.c 2020-02-22 14:33:47.775736302 +0200 @@ -22,6 +22,9 @@ #include #include @@ -20,8 +20,8 @@ diff -Nurd tolua-5.2/src/bin/tolua.c tolua-5.2/src/bin/tolua.c } #else diff -Nurd tolua-5.2/src/lib/tolua_event.c tolua-5.2/src/lib/tolua_event.c ---- tolua-5.2/src/lib/tolua_event.c 2016-01-06 01:19:24.980940147 +0200 -+++ tolua-5.2/src/lib/tolua_event.c 2016-01-06 01:20:07.884846927 +0200 +--- tolua-5.2/src/lib/tolua_event.c 2022-01-27 13:47:57.409903222 +0200 ++++ tolua-5.2/src/lib/tolua_event.c 2022-01-27 13:48:23.538116437 +0200 @@ -18,6 +18,8 @@ #include "tolua.h" @@ -31,9 +31,19 @@ diff -Nurd tolua-5.2/src/lib/tolua_event.c tolua-5.2/src/lib/tolua_event.c /* Store at peer * It stores, creating the corresponding table if needed, * the pair key/value in the corresponding peer table +@@ -391,8 +393,8 @@ + } + else if (lua_isuserdata(L,-1) && *((void**)lua_touserdata(L,-1))==NULL) { + /* free object */ +- free(u); + tolua_release(L,u); /* unmap from tolua tables */ ++ free(u); + } + } + lua_settop(L,top); diff -Nurd tolua-5.2/src/lib/tolua_map.c tolua-5.2/src/lib/tolua_map.c ---- tolua-5.2/src/lib/tolua_map.c 2016-01-06 01:19:24.980940147 +0200 -+++ tolua-5.2/src/lib/tolua_map.c 2016-01-06 01:20:48.972757711 +0200 +--- tolua-5.2/src/lib/tolua_map.c 2022-01-27 13:47:57.409903222 +0200 ++++ tolua-5.2/src/lib/tolua_map.c 2020-02-22 14:33:47.779735894 +0200 @@ -21,6 +21,7 @@ #include #include diff --git a/dependencies/tolua-5.2/src/lib/tolua_event.c b/dependencies/tolua-5.2/src/lib/tolua_event.c index 0996838176..f2a6a1f77a 100644 --- a/dependencies/tolua-5.2/src/lib/tolua_event.c +++ b/dependencies/tolua-5.2/src/lib/tolua_event.c @@ -393,8 +393,8 @@ static int class_gc_event (lua_State* L) } else if (lua_isuserdata(L,-1) && *((void**)lua_touserdata(L,-1))==NULL) { /* free object */ - free(u); tolua_release(L,u); /* unmap from tolua tables */ + free(u); } } lua_settop(L,top); -- 2.34.1