From: Michael Tremer Date: Thu, 22 Feb 2024 15:13:41 +0000 (+0000) Subject: lua: Don't try to free memory that was allocated by Lua X-Git-Tag: 0.9.18~154 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75448a0237a915ebb3147ed6de4deedb7c756527;p=location%2Flibloc.git lua: Don't try to free memory that was allocated by Lua The userdata that we have allocated cannot be freed as we don't have control over it. Signed-off-by: Michael Tremer --- diff --git a/src/lua/country.c b/src/lua/country.c index 5a9652e..7012ee6 100644 --- a/src/lua/country.c +++ b/src/lua/country.c @@ -72,7 +72,7 @@ static int Country_new(lua_State* L) { return r; } -static int Country_close(lua_State* L) { +static int Country_gc(lua_State* L) { Country* self = luaL_checkcountry(L, 1); // Free country @@ -84,15 +84,6 @@ static int Country_close(lua_State* L) { return 0; } -static int Country_gc(lua_State* L) { - Country* self = luaL_checkcountry(L, 1); - - // Free the object - free(self); - - return 0; -} - static int Country_eq(lua_State* L) { Country* self = luaL_checkcountry(L, 1); Country* other = luaL_checkcountry(L, 2); @@ -115,7 +106,6 @@ static int Country_get_code(lua_State* L) { static const struct luaL_Reg Country_functions[] = { { "new", Country_new }, { "get_code", Country_get_code }, - { "__close", Country_close }, { "__eq", Country_eq }, { "__gc", Country_gc }, { NULL, NULL }, diff --git a/src/lua/database.c b/src/lua/database.c index 2d97dcf..efed6aa 100644 --- a/src/lua/database.c +++ b/src/lua/database.c @@ -71,7 +71,7 @@ static int Database_open(lua_State* L) { return 1; } -static int Database_close(lua_State* L) { +static int Database_gc(lua_State* L) { Database* self = luaL_checkdatabase(L, 1); // Free database @@ -83,15 +83,6 @@ static int Database_close(lua_State* L) { return 0; } -static int Database_gc(lua_State* L) { - Database* self = luaL_checkdatabase(L, 1); - - // Free the object - free(self); - - return 0; -} - static int Database_lookup(lua_State* L) { struct loc_network* network = NULL; int r; @@ -116,7 +107,6 @@ static int Database_lookup(lua_State* L) { static const struct luaL_Reg database_functions[] = { { "open", Database_open }, { "lookup", Database_lookup }, - { "__close", Database_close }, { "__gc", Database_gc }, { NULL, NULL }, }; diff --git a/src/lua/network.c b/src/lua/network.c index 8a75559..12750d5 100644 --- a/src/lua/network.c +++ b/src/lua/network.c @@ -72,7 +72,7 @@ static int Network_new(lua_State* L) { return r; } -static int Network_close(lua_State* L) { +static int Network_gc(lua_State* L) { Network* self = luaL_checknetwork(L, 1); // Free the network @@ -84,15 +84,6 @@ static int Network_close(lua_State* L) { return 0; } -static int Network_gc(lua_State* L) { - Network* self = luaL_checknetwork(L, 1); - - // Free the object - free(self); - - return 0; -} - static int Network_tostring(lua_State* L) { Network* self = luaL_checknetwork(L, 1); @@ -150,7 +141,6 @@ static const struct luaL_Reg Network_functions[] = { { "get_asn", Network_get_asn }, { "get_family", Network_get_family }, { "get_country_code", Network_get_country_code }, - { "__close", Network_close }, { "__gc", Network_gc }, { "__tostring", Network_tostring }, { NULL, NULL },