]> git.ipfire.org Git - location/libloc.git/commitdiff
lua: Don't try to free memory that was allocated by Lua
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 15:13:41 +0000 (15:13 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 15:13:41 +0000 (15:13 +0000)
The userdata that we have allocated cannot be freed as we don't have
control over it.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/lua/country.c
src/lua/database.c
src/lua/network.c

index 5a9652e3d50919a1ecd9b44e91b6791c0e2106dc..7012ee69ddfcb115d5c1d73cc20917a01fc61a7f 100644 (file)
@@ -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 },
index 2d97dcf854661d12a0661be9943093256cc003a9..efed6aaf9ce9d08b70d70cb4c0cc7f13621050bf 100644 (file)
@@ -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 },
 };
index 8a755595cf6829ef407088f5164ae44ca53ebaa3..12750d55f44361b4c21cb18ff32e3933c5244a99 100644 (file)
@@ -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 },