From 1eaefef5a8921aa476ab7f381071125ad4ac156b Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Mon, 12 Feb 2024 14:32:54 +0100 Subject: [PATCH] libdnf: switch from g_error_free() to g_clear_error() in tests Use g_clear_error() so the pointer is also reset to NULL; this avoids potential wrong non-null checks and double frees. Card ID: CCT-368 --- src/plugins/libdnf/test-productdb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/plugins/libdnf/test-productdb.c b/src/plugins/libdnf/test-productdb.c index e54233b6fb..8369029c9a 100644 --- a/src/plugins/libdnf/test-productdb.c +++ b/src/plugins/libdnf/test-productdb.c @@ -117,7 +117,7 @@ void testReadMissingFile(dbFixture *fixture, gconstpointer ignored) { GError *err = NULL; readProductDb(db, &err); g_assert_nonnull(err); - g_error_free(err); + g_clear_error(&err); } void testReadFile(dbFixture *fixture, gconstpointer ignored) { @@ -151,7 +151,7 @@ void testReadFile(dbFixture *fixture, gconstpointer ignored) { g_object_unref(ioStream); g_object_unref(testJsonFile); if(err != NULL) { - g_error_free(err); + g_clear_error(&err); } } @@ -178,7 +178,7 @@ void testReadCorruptedFile(dbFixture *fixture, gconstpointer ignored) { readProductDb(db, &err); g_assert_nonnull(err); - g_error_free(err); + g_clear_error(&err); g_assert_cmpint(g_hash_table_size(db->repoMap), ==, 0); } @@ -204,7 +204,7 @@ void testReadFileWrongData(dbFixture *fixture, gconstpointer ignored) { g_output_stream_write_all(outStream, testJson01, strlen(testJson01), NULL, NULL, &err); readProductDb(db, &err); g_assert_nonnull(err); - g_error_free(err); + g_clear_error(&err); // Key is not string, but it is integer gchar *testJson02 = "{69: ['rhel']}\n"; @@ -212,7 +212,7 @@ void testReadFileWrongData(dbFixture *fixture, gconstpointer ignored) { g_output_stream_write_all(outStream, testJson02, strlen(testJson02), NULL, NULL, &err); readProductDb(db, &err); g_assert_nonnull(err); - g_error_free(err); + g_clear_error(&err); // Value in array is not string, but it is integer gchar *testJson03 = "{'69': [100]}\n"; @@ -220,7 +220,7 @@ void testReadFileWrongData(dbFixture *fixture, gconstpointer ignored) { g_output_stream_write_all(outStream, testJson03, strlen(testJson03), NULL, NULL, &err); readProductDb(db, &err); g_assert_nonnull(err); - g_error_free(err); + g_clear_error(&err); g_io_stream_close((GIOStream*) ioStream, NULL, &err); }