Commit c820094d authored by Michael Tremer's avatar Michael Tremer

perl: Release location context when opening the database fails

Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent 74ad091d
...@@ -16,7 +16,7 @@ MODULE = Location PACKAGE = Location ...@@ -16,7 +16,7 @@ MODULE = Location PACKAGE = Location
struct loc_database * struct loc_database *
init(file) init(file)
char * file; char* file = NULL;
CODE: CODE:
struct loc_ctx* ctx = NULL; struct loc_ctx* ctx = NULL;
...@@ -29,17 +29,24 @@ init(file) ...@@ -29,17 +29,24 @@ init(file)
// Open the database file for reading // Open the database file for reading
FILE* f = fopen(file, "r"); FILE* f = fopen(file, "r");
if (!f) { if (!f) {
loc_unref(ctx);
croak("Could not open file for reading: %s: %s\n", croak("Could not open file for reading: %s: %s\n",
file, strerror(errno)); file, strerror(errno));
} }
// Parse the database // Parse the database
struct loc_database *db = NULL; struct loc_database* db = NULL;
err = loc_database_new(ctx, &db, f); err = loc_database_new(ctx, &db, f);
if (err) { if (err) {
loc_unref(ctx);
croak("Could not read database: %s\n", file); croak("Could not read database: %s\n", file);
} }
// Cleanup
loc_unref(ctx);
RETVAL = db; RETVAL = db;
OUTPUT: OUTPUT:
RETVAL RETVAL
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment