From 94be128ba017472cc43f011571a69636a168fa98 Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Thu, 22 Feb 2024 14:33:43 +0100 Subject: [PATCH 1/4] Removed unused includes of .h files * There were some unused includes in product-id.c and unit test files --- src/plugins/libdnf/product-id.c | 3 --- src/plugins/libdnf/test-product-id.c | 1 - src/plugins/libdnf/test-productdb.c | 1 - 3 files changed, 5 deletions(-) diff --git a/src/plugins/libdnf/product-id.c b/src/plugins/libdnf/product-id.c index 02f15f7ff5..035f976105 100644 --- a/src/plugins/libdnf/product-id.c +++ b/src/plugins/libdnf/product-id.c @@ -21,11 +21,8 @@ #include #include -#include - #include #include -#include #include #include #include diff --git a/src/plugins/libdnf/test-product-id.c b/src/plugins/libdnf/test-product-id.c index e7dc99e29f..51bf814ccd 100644 --- a/src/plugins/libdnf/test-product-id.c +++ b/src/plugins/libdnf/test-product-id.c @@ -13,7 +13,6 @@ * in this software or its documentation. */ -#include #include #include #include diff --git a/src/plugins/libdnf/test-productdb.c b/src/plugins/libdnf/test-productdb.c index 8369029c9a..018eb3b951 100644 --- a/src/plugins/libdnf/test-productdb.c +++ b/src/plugins/libdnf/test-productdb.c @@ -14,7 +14,6 @@ */ #include -#include #include #include From d326b0536f4e674528e54652519510081defece0 Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Thu, 22 Feb 2024 15:16:27 +0100 Subject: [PATCH 2/4] fix: Function prototype without declaration is deprecated * Added void to prototype of initRepoProductId() --- src/plugins/libdnf/product-id.c | 2 +- src/plugins/libdnf/product-id.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/libdnf/product-id.c b/src/plugins/libdnf/product-id.c index 035f976105..ba69b75b91 100644 --- a/src/plugins/libdnf/product-id.c +++ b/src/plugins/libdnf/product-id.c @@ -160,7 +160,7 @@ gchar *strHookId(PluginHookId id) { } } -RepoProductId *initRepoProductId() { +RepoProductId *initRepoProductId(void) { RepoProductId *repoProductId = (RepoProductId*) malloc(sizeof(RepoProductId)); repoProductId->repo = NULL; repoProductId->productIdPath = NULL; diff --git a/src/plugins/libdnf/product-id.h b/src/plugins/libdnf/product-id.h index 609749d2c0..71b4ee5764 100644 --- a/src/plugins/libdnf/product-id.h +++ b/src/plugins/libdnf/product-id.h @@ -68,7 +68,7 @@ typedef struct { bool isInstalled; } RepoProductId; -RepoProductId *initRepoProductId(); +RepoProductId *initRepoProductId(void); void freeRepoProductId(RepoProductId *repoProductId); void printError(const char *msg, GError *err); void getEnabled(const GPtrArray *repos, GPtrArray *enabledRepos); From b7a359634512ba916258b3b42c86273230b47d0a Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Thu, 22 Feb 2024 16:45:51 +0100 Subject: [PATCH 3/4] Fix memory leaks in productdb.c * When reading of JSON file fails, then do not forget to free object representing JSON file. Fix indentation. --- src/plugins/libdnf/productdb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plugins/libdnf/productdb.c b/src/plugins/libdnf/productdb.c index f7a523ae94..0de6906b49 100644 --- a/src/plugins/libdnf/productdb.c +++ b/src/plugins/libdnf/productdb.c @@ -101,6 +101,7 @@ void readProductDb(ProductDb *productDb, GError **err) { if (repoIds == NULL) { *err = g_error_new_literal(quark, 0, error_string); g_free(productId); + json_object_put(dbJson); return; } GSList *repoList = NULL; @@ -109,6 +110,7 @@ void readProductDb(ProductDb *productDb, GError **err) { if (idArray == NULL) { *err = g_error_new_literal(quark, 0, error_string); g_free(productId); + json_object_put(dbJson); return; } int len = array_list_length(idArray); @@ -119,6 +121,7 @@ void readProductDb(ProductDb *productDb, GError **err) { if (repoId == NULL) { *err = g_error_new_literal(quark, 0, error_string); g_free(productId); + json_object_put(dbJson); return; } repoList = g_slist_prepend(repoList, (gpointer) repoId); From 01f65d273f9f933c59abbc6a1abe6e99ad8c43c5 Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Thu, 22 Feb 2024 16:50:24 +0100 Subject: [PATCH 4/4] Fix memory leaks in test-productdb.c * Fixed several memory leaks in test-productdb.c --- src/plugins/libdnf/test-productdb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/libdnf/test-productdb.c b/src/plugins/libdnf/test-productdb.c index 018eb3b951..3c708c4ec6 100644 --- a/src/plugins/libdnf/test-productdb.c +++ b/src/plugins/libdnf/test-productdb.c @@ -179,6 +179,8 @@ void testReadCorruptedFile(dbFixture *fixture, gconstpointer ignored) { g_assert_nonnull(err); g_clear_error(&err); g_assert_cmpint(g_hash_table_size(db->repoMap), ==, 0); + g_free(path); + g_object_unref(testJsonFile); } void testReadFileWrongData(dbFixture *fixture, gconstpointer ignored) { @@ -222,6 +224,8 @@ void testReadFileWrongData(dbFixture *fixture, gconstpointer ignored) { g_clear_error(&err); g_io_stream_close((GIOStream*) ioStream, NULL, &err); + g_free(path); + g_object_unref(testJsonFile); } void testWriteFile(dbFixture *fixture, gconstpointer ignored) {