]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/database.c
database: Free mmapped countries section
[people/ms/libloc.git] / src / database.c
index 7100298b3de866f467b4e2ca3cbb567da32eec0c..b92a803d5d3db9a8be49049ee803d7a06f6180e2 100644 (file)
@@ -446,6 +446,13 @@ static void loc_database_free(struct loc_database* db) {
                        ERROR(db->ctx, "Could not unmap network nodes section: %s\n", strerror(errno));
        }
 
+       // Remove mapped countries section
+       if (db->countries_v1) {
+               r = munmap(db->countries_v1, db->countries_count * sizeof(*db->countries_v1));
+               if (r)
+                       ERROR(db->ctx, "Could not unmap countries section: %s\n", strerror(errno));
+       }
+
        if (db->pool)
                loc_stringpool_unref(db->pool);
 
@@ -1380,11 +1387,10 @@ static int __loc_database_enumerator_next_network_flattened(
        loc_network_list_unref(subnets);
        loc_network_list_unref(excluded);
 
-       // Replace network with the first one from the stack
+       // Drop the network and restart the whole process again to pick the next network
        loc_network_unref(*network);
-       *network = loc_network_list_pop_first(enumerator->stack);
 
-       return 0;
+       return __loc_database_enumerator_next_network_flattened(enumerator, network);
 }
 
 LOC_EXPORT int loc_database_enumerator_next_network(