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