]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
location-functions.pl: Use a single script-wide db_handle.
authorStefan Schantl <stefan.schantl@ipfire.org>
Sat, 7 Nov 2020 18:47:20 +0000 (19:47 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 Nov 2020 14:06:53 +0000 (14:06 +0000)
Create and use a single script-wide database handle for libloc to
prevent from creating multiple ones.

This helps saving memory, especially on small systems.

Reference #12515.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/cfgroot/location-functions.pl

index 2cfe7f908fd92db2dd7c49be5630d8337bf2de79..9b1d0bfb5018e032bce12c733c6b108c4b6f92c2 100644 (file)
@@ -55,6 +55,9 @@ our $keyfile = "$location_dir/signing-key.pem";
 # Directory which contains the exported databases.
 our $xt_geoip_db_directory = "/usr/share/xt_geoip/";
 
+# Create libloc database handle.
+my $db_handle = &init();
+
 #
 ## Tiny function to init the location database.
 #
@@ -86,7 +89,7 @@ sub verify ($) {
 ## Function to the the country code of a given address.
 #
 sub lookup_country_code($$) {
-       my ($db_handle, $address) = @_;
+       my ($address) = @_;
 
        # Lookup the given address.
        my $country_code = &Location::lookup_country_code($db_handle, $address);
@@ -174,9 +177,6 @@ sub get_full_country_name($) {
 
 # Function to get all available locations.
 sub get_locations() {
-       # Create libloc database handle.
-       my $db_handle = &init();
-
        # Get locations which are stored in the location database.
        my @database_locations = &Location::database_countries($db_handle);
 
@@ -197,9 +197,6 @@ sub address_has_flags($) {
        # Array to store the flags of the address.
        my @flags;
 
-       # Init libloc database handle.
-       my $db_handle = &init();
-
        # Loop through the hash of possible network flags.
        foreach my $flag (keys(%network_flags)) {
                # Check if the address has the current flag.