Blame SOURCES/0002-Fix-alloc-free-mismatches-from-covscan.patch

7bb93f
From 493226f298b3d81e4b01d9f2c64a1cc2eb3049e4 Mon Sep 17 00:00:00 2001
7bb93f
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
7bb93f
Date: Fri, 15 Jul 2022 17:16:12 +0200
7bb93f
Subject: [PATCH] Fix alloc / free mismatches from covscan
7bb93f
7bb93f
---
7bb93f
 librepo/checksum.c           |  6 +++---
7bb93f
 librepo/downloader.c         |  2 +-
7bb93f
 librepo/lrmirrorlist.c       |  2 +-
7bb93f
 librepo/package_downloader.c |  2 +-
7bb93f
 librepo/repoconf.c           |  2 +-
7bb93f
 librepo/repoutil_yum.c       |  4 ++--
7bb93f
 librepo/util.c               |  6 +++---
7bb93f
 tests/test_checksum.c        |  4 ++--
7bb93f
 tests/test_gpg.c             |  2 +-
7bb93f
 tests/test_main.c            |  2 +-
7bb93f
 tests/test_util.c            | 24 ++++++++++++------------
7bb93f
 11 files changed, 28 insertions(+), 28 deletions(-)
7bb93f
7bb93f
diff --git a/librepo/checksum.c b/librepo/checksum.c
7bb93f
index d82cb5c..4831ddc 100644
7bb93f
--- a/librepo/checksum.c
7bb93f
+++ b/librepo/checksum.c
7bb93f
@@ -205,8 +205,6 @@ lr_checksum_fd_compare(LrChecksumType type,
7bb93f
                        gchar **calculated,
7bb93f
                        GError **err)
7bb93f
 {
7bb93f
-    _cleanup_free_ gchar *checksum = NULL;
7bb93f
-
7bb93f
     assert(fd >= 0);
7bb93f
     assert(!err || *err == NULL);
7bb93f
 
7bb93f
@@ -262,7 +260,7 @@ lr_checksum_fd_compare(LrChecksumType type,
7bb93f
         }
7bb93f
     }
7bb93f
 
7bb93f
-    checksum = lr_checksum_fd(type, fd, err);
7bb93f
+    char *checksum = lr_checksum_fd(type, fd, err);
7bb93f
     if (!checksum)
7bb93f
         return FALSE;
7bb93f
 
7bb93f
@@ -274,6 +272,7 @@ lr_checksum_fd_compare(LrChecksumType type,
7bb93f
         } else {
7bb93f
             g_set_error(err, LR_CHECKSUM_ERROR, LRE_FILE,
7bb93f
                         "fsync failed: %s", strerror(errno));
7bb93f
+            lr_free(checksum);
7bb93f
             return FALSE;
7bb93f
         }
7bb93f
     }
7bb93f
@@ -287,6 +286,7 @@ lr_checksum_fd_compare(LrChecksumType type,
7bb93f
     if (calculated)
7bb93f
         *calculated = g_strdup(checksum);
7bb93f
 
7bb93f
+    lr_free(checksum);
7bb93f
     return TRUE;
7bb93f
 }
7bb93f
 
7bb93f
diff --git a/librepo/downloader.c b/librepo/downloader.c
7bb93f
index f4e8ba2..84739a9 100644
7bb93f
--- a/librepo/downloader.c
7bb93f
+++ b/librepo/downloader.c
7bb93f
@@ -1974,7 +1974,7 @@ list_of_checksums_to_str(GSList *checksums)
7bb93f
         tmp = g_strconcat(expected, chksum->value, "(",
7bb93f
                           chtype_str ? chtype_str : "UNKNOWN",
7bb93f
                           ") ", NULL);
7bb93f
-        free(expected);
7bb93f
+        g_free(expected);
7bb93f
         expected = tmp;
7bb93f
     }
7bb93f
 
7bb93f
diff --git a/librepo/lrmirrorlist.c b/librepo/lrmirrorlist.c
7bb93f
index c7e51b3..91cdc4b 100644
7bb93f
--- a/librepo/lrmirrorlist.c
7bb93f
+++ b/librepo/lrmirrorlist.c
7bb93f
@@ -156,7 +156,7 @@ lr_lrmirrorlist_append_metalink(LrInternalMirrorlist *list,
7bb93f
         LrInternalMirror *mirror = lr_lrmirror_new(url_copy, urlvars);
7bb93f
         mirror->preference = metalinkurl->preference;
7bb93f
         mirror->protocol = lr_detect_protocol(mirror->url);
7bb93f
-        lr_free(url_copy);
7bb93f
+        g_free(url_copy);
7bb93f
         list = g_slist_append(list, mirror);
7bb93f
 
7bb93f
         //g_debug("%s: Appending URL: %s", __func__, mirror->url);
7bb93f
diff --git a/librepo/package_downloader.c b/librepo/package_downloader.c
7bb93f
index adea459..353cac8 100644
7bb93f
--- a/librepo/package_downloader.c
7bb93f
+++ b/librepo/package_downloader.c
7bb93f
@@ -173,7 +173,7 @@ lr_packagetarget_free(LrPackageTarget *target)
7bb93f
     if (!target)
7bb93f
         return;
7bb93f
     g_string_chunk_free(target->chunk);
7bb93f
-    g_free(target);
7bb93f
+    lr_free(target);
7bb93f
 }
7bb93f
 
7bb93f
 gboolean
7bb93f
diff --git a/librepo/repoconf.c b/librepo/repoconf.c
7bb93f
index 948259e..34dbab4 100644
7bb93f
--- a/librepo/repoconf.c
7bb93f
+++ b/librepo/repoconf.c
7bb93f
@@ -146,7 +146,7 @@ lr_yum_repoconfs_free(LrYumRepoConfs *repos)
7bb93f
         return;
7bb93f
     g_slist_free_full(repos->repos, (GDestroyNotify) lr_yum_repoconf_free);
7bb93f
     g_slist_free_full(repos->files, (GDestroyNotify) lr_yum_repofile_free);
7bb93f
-    g_free(repos);
7bb93f
+    lr_free(repos);
7bb93f
 }
7bb93f
 
7bb93f
 GSList *
7bb93f
diff --git a/librepo/repoutil_yum.c b/librepo/repoutil_yum.c
7bb93f
index 02e796f..bb09ff5 100644
7bb93f
--- a/librepo/repoutil_yum.c
7bb93f
+++ b/librepo/repoutil_yum.c
7bb93f
@@ -105,11 +105,11 @@ lr_repoutil_yum_parse_repomd(const char *in_path,
7bb93f
     if (fd < 0) {
7bb93f
         g_set_error(err, LR_REPOUTIL_YUM_ERROR, LRE_IO,
7bb93f
                     "open(%s, O_RDONLY) error: %s", path, g_strerror(errno));
7bb93f
-        lr_free(path);
7bb93f
+        g_free(path);
7bb93f
         return FALSE;
7bb93f
     }
7bb93f
 
7bb93f
-    lr_free(path);
7bb93f
+    g_free(path);
7bb93f
 
7bb93f
     ret = lr_yum_repomd_parse_file(repomd, fd, NULL, NULL, err);
7bb93f
     close(fd);
7bb93f
diff --git a/librepo/util.c b/librepo/util.c
7bb93f
index 8ba7120..204572d 100644
7bb93f
--- a/librepo/util.c
7bb93f
+++ b/librepo/util.c
7bb93f
@@ -170,7 +170,7 @@ lr_gettmpdir(void)
7bb93f
 {
7bb93f
     char *template = g_build_filename(g_get_tmp_dir(), "librepo-tmpdir-XXXXXX", NULL);
7bb93f
     if (!mkdtemp(template)) {
7bb93f
-        lr_free(template);
7bb93f
+        g_free(template);
7bb93f
         return NULL;
7bb93f
     }
7bb93f
     return template;
7bb93f
@@ -206,7 +206,7 @@ lr_pathconcat(const char *first, ...)
7bb93f
 
7bb93f
     qmark_section = strchr(first, '?');
7bb93f
 
7bb93f
-    res = lr_malloc(total_len + separator_len + 1);
7bb93f
+    res = g_malloc(total_len + separator_len + 1);
7bb93f
 
7bb93f
     next = first;
7bb93f
     va_start(args, first);
7bb93f
@@ -273,7 +273,7 @@ lr_pathconcat(const char *first, ...)
7bb93f
     assert(offset <= total_len);
7bb93f
 
7bb93f
     if (offset == 0) {
7bb93f
-        lr_free(res);
7bb93f
+        g_free(res);
7bb93f
         return g_strdup(first);
7bb93f
     }
7bb93f
 
7bb93f
diff --git a/tests/test_checksum.c b/tests/test_checksum.c
7bb93f
index 548f588..264782c 100644
7bb93f
--- a/tests/test_checksum.c
7bb93f
+++ b/tests/test_checksum.c
7bb93f
@@ -295,8 +295,8 @@ START_TEST(test_cached_checksum_clear)
7bb93f
 cleanup:
7bb93f
     close(fd);
7bb93f
     lr_free(filename);
7bb93f
-    lr_free(timestamp_key);
7bb93f
-    lr_free(checksum_key);
7bb93f
+    g_free(timestamp_key);
7bb93f
+    g_free(checksum_key);
7bb93f
 }
7bb93f
 END_TEST
7bb93f
 
7bb93f
diff --git a/tests/test_gpg.c b/tests/test_gpg.c
7bb93f
index fd322e3..0af423a 100644
7bb93f
--- a/tests/test_gpg.c
7bb93f
+++ b/tests/test_gpg.c
7bb93f
@@ -110,7 +110,7 @@ START_TEST(test_gpg_check_signature)
7bb93f
     lr_free(_data_path);
7bb93f
     lr_free(signature_path);
7bb93f
     lr_free(_signature_path);
7bb93f
-    lr_free(tmp_home_path);
7bb93f
+    g_free(tmp_home_path);
7bb93f
 }
7bb93f
 END_TEST
7bb93f
 
7bb93f
diff --git a/tests/test_main.c b/tests/test_main.c
7bb93f
index 1076062..b323ce5 100644
7bb93f
--- a/tests/test_main.c
7bb93f
+++ b/tests/test_main.c
7bb93f
@@ -39,7 +39,7 @@ init_test_globals(struct TestGlobals_s *tg, const char *testdata_dir)
7bb93f
 static void
7bb93f
 free_test_globals(struct TestGlobals_s *tg)
7bb93f
 {
7bb93f
-    lr_free(tg->tmpdir);
7bb93f
+    g_free(tg->tmpdir);
7bb93f
     lr_free(tg->testdata_dir);
7bb93f
 }
7bb93f
 
7bb93f
diff --git a/tests/test_util.c b/tests/test_util.c
7bb93f
index 595b0fe..d082445 100644
7bb93f
--- a/tests/test_util.c
7bb93f
+++ b/tests/test_util.c
7bb93f
@@ -54,7 +54,7 @@ START_TEST(test_gettmpdir)
7bb93f
     char *tmp_dir = lr_gettmpdir();
7bb93f
     ck_assert_ptr_nonnull(tmp_dir);
7bb93f
     ck_assert_int_eq(rmdir(tmp_dir), 0);
7bb93f
-    lr_free(tmp_dir);
7bb93f
+    g_free(tmp_dir);
7bb93f
 }
7bb93f
 END_TEST
7bb93f
 
7bb93f
@@ -126,7 +126,7 @@ START_TEST(test_remove_dir)
7bb93f
     ck_assert_int_eq(rc, 0);
7bb93f
     ck_assert_int_ne(unlink(tmp_file), 0);
7bb93f
     ck_assert_int_ne(rmdir(tmp_dir), 0);
7bb93f
-    lr_free(tmp_dir);
7bb93f
+    g_free(tmp_dir);
7bb93f
     lr_free(tmp_file);
7bb93f
 }
7bb93f
 END_TEST
7bb93f
@@ -141,61 +141,61 @@ START_TEST(test_url_without_path)
7bb93f
     new_url = lr_url_without_path("");
7bb93f
     ck_assert_ptr_nonnull(new_url);
7bb93f
     ck_assert_str_eq(new_url, "");
7bb93f
-    lr_free(new_url);
7bb93f
+    g_free(new_url);
7bb93f
     new_url = NULL;
7bb93f
 
7bb93f
     new_url = lr_url_without_path("hostname");
7bb93f
     ck_assert_ptr_nonnull(new_url);
7bb93f
     ck_assert_str_eq(new_url, "hostname");
7bb93f
-    lr_free(new_url);
7bb93f
+    g_free(new_url);
7bb93f
     new_url = NULL;
7bb93f
 
7bb93f
     new_url = lr_url_without_path("hostname/foo/bar/");
7bb93f
     ck_assert_ptr_nonnull(new_url);
7bb93f
     ck_assert_str_eq(new_url, "hostname");
7bb93f
-    lr_free(new_url);
7bb93f
+    g_free(new_url);
7bb93f
     new_url = NULL;
7bb93f
 
7bb93f
     new_url = lr_url_without_path("hostname:80");
7bb93f
     ck_assert_ptr_nonnull(new_url);
7bb93f
     ck_assert_str_eq(new_url, "hostname:80");
7bb93f
-    lr_free(new_url);
7bb93f
+    g_free(new_url);
7bb93f
     new_url = NULL;
7bb93f
 
7bb93f
     new_url = lr_url_without_path("hostname:80/foo/bar");
7bb93f
     ck_assert_ptr_nonnull(new_url);
7bb93f
     ck_assert_str_eq(new_url, "hostname:80");
7bb93f
-    lr_free(new_url);
7bb93f
+    g_free(new_url);
7bb93f
     new_url = NULL;
7bb93f
 
7bb93f
     new_url = lr_url_without_path("http://hostname:80/");
7bb93f
     ck_assert_ptr_nonnull(new_url);
7bb93f
     ck_assert_str_eq(new_url, "http://hostname:80");
7bb93f
-    lr_free(new_url);
7bb93f
+    g_free(new_url);
7bb93f
     new_url = NULL;
7bb93f
 
7bb93f
     new_url = lr_url_without_path("http://hostname:80/foo/bar");
7bb93f
     ck_assert_ptr_nonnull(new_url);
7bb93f
     ck_assert_str_eq(new_url, "http://hostname:80");
7bb93f
-    lr_free(new_url);
7bb93f
+    g_free(new_url);
7bb93f
     new_url = NULL;
7bb93f
 
7bb93f
     new_url = lr_url_without_path("ftp://foo.hostname:80/foo/bar");
7bb93f
     ck_assert_ptr_nonnull(new_url);
7bb93f
     ck_assert_str_eq(new_url, "ftp://foo.hostname:80");
7bb93f
-    lr_free(new_url);
7bb93f
+    g_free(new_url);
7bb93f
     new_url = NULL;
7bb93f
 
7bb93f
     new_url = lr_url_without_path("file:///home/foobar");
7bb93f
     ck_assert_ptr_nonnull(new_url);
7bb93f
     ck_assert_str_eq(new_url, "file://");
7bb93f
-    lr_free(new_url);
7bb93f
+    g_free(new_url);
7bb93f
     new_url = NULL;
7bb93f
 
7bb93f
     new_url = lr_url_without_path("file:/home/foobar");
7bb93f
     ck_assert_ptr_nonnull(new_url);
7bb93f
     ck_assert_str_eq(new_url, "file://");
7bb93f
-    lr_free(new_url);
7bb93f
+    g_free(new_url);
7bb93f
     new_url = NULL;
7bb93f
 }
7bb93f
 END_TEST
7bb93f
-- 
7bb93f
2.37.1
7bb93f