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