]> git.ipfire.org Git - location/libloc.git/commitdiff
perl: Release location context when opening the database fails
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 Sep 2019 17:39:38 +0000 (17:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 Sep 2019 17:39:38 +0000 (17:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/perl/Location/Location.xs

index 02f447aaa8bdbf5402199588f32e1c268b33d89d..1b01c22c8b995d037098b4e9fba31f82d6ab0339 100644 (file)
@@ -16,7 +16,7 @@ MODULE = Location             PACKAGE = Location
 
 struct loc_database *
 init(file)
-       char * file;
+       char* file = NULL;
 
        CODE:
                struct loc_ctx* ctx = NULL;
@@ -29,17 +29,24 @@ init(file)
                // Open the database file for reading
                FILE* f = fopen(file, "r");
                if (!f) {
+                       loc_unref(ctx);
+
                        croak("Could not open file for reading: %s: %s\n",
                                file, strerror(errno));
                }
 
                // Parse the database
-               struct loc_database *db = NULL;
+               struct loc_databasedb = NULL;
                err = loc_database_new(ctx, &db, f);
                if (err) {
+                       loc_unref(ctx);
+
                        croak("Could not read database: %s\n", file);
                }
 
+               // Cleanup
+               loc_unref(ctx);
+
                RETVAL = db;
        OUTPUT:
                RETVAL