From: Michael Tremer Date: Wed, 8 Mar 2023 11:46:16 +0000 (+0000) Subject: repo: Ensure to close the file descriptor after reading the database X-Git-Tag: 0.9.29~353 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4af3ee361a67110b969327a312509d109650cee7;p=pakfire.git repo: Ensure to close the file descriptor after reading the database Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 7789f0f4c..92924e811 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -330,6 +330,7 @@ static int pakfire_repo_download_database(struct pakfire_repo* repo, const char* } static int pakfire_repo_read_metadata(struct pakfire_repo* repo, const char* path, int refresh) { + FILE* f = NULL; int r; struct json_object* json = pakfire_json_parse_from_file(repo->pakfire, path); @@ -375,13 +376,12 @@ static int pakfire_repo_read_metadata(struct pakfire_repo* repo, const char* pat goto ERROR; // Open database file - FILE* f = fopen(database_cache_path, "r"); + f = fopen(database_cache_path, "r"); if (!f) goto ERROR; // Read database r = pakfire_repo_read_solv(repo, f, 0); - fclose(f); if (r) { if (!refresh && errno == ENOENT) goto NOERROR; @@ -396,6 +396,9 @@ NOERROR: r = 0; ERROR: + if (f) + fclose(f); + // Free the parsed JSON object json_object_put(json);