From 756b9eae14087d4331c774d9973cb5fee9f1502d Mon Sep 17 00:00:00 2001 From: Phaedrus Leeds Date: Sun, 2 May 2021 20:49:03 -0500 Subject: [PATCH] common: Fix several memory leaks --- common/flatpak-dir.c | 12 ++++++------ common/flatpak-progress.c | 4 ++-- common/flatpak-utils.c | 4 +++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index 9fc8920c..3aabd846 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -11812,6 +11812,7 @@ flatpak_dir_remote_fetch_indexed_summary (FlatpakDir *self, if (summary == NULL) return FALSE; + g_free (sha256); sha256 = g_compute_checksum_for_bytes (G_CHECKSUM_SHA256, summary); if (strcmp (sha256, checksum) != 0) return flatpak_fail_error (error, FLATPAK_ERROR_INVALID_DATA, _("Invalid checksum for indexed summary %s for remote '%s'"), checksum, name_or_uri); @@ -12466,12 +12467,11 @@ find_matching_ref (GHashTable *refs, g_string_append (err, ", "); const char *branch = flatpak_decomposed_get_branch (ref); - - g_string_append (err, - g_strdup_printf ("%s/%s/%s", - name, - opt_arch ? opt_arch : "", - branch)); + g_string_append_printf (err, + "%s/%s/%s", + name, + opt_arch ? opt_arch : "", + branch); } flatpak_fail (error, "%s", err->str); diff --git a/common/flatpak-progress.c b/common/flatpak-progress.c index 7a0ea020..1e8842ae 100644 --- a/common/flatpak-progress.c +++ b/common/flatpak-progress.c @@ -186,8 +186,6 @@ update_status_progress_and_estimating (FlatpakProgress *self) gboolean last_was_metadata = self->last_was_metadata; g_autofree gchar *formatted_bytes_total_transferred = NULL; - buf = g_string_new (""); - /* We get some extra calls before we've really started due to the initialization of the extra data, so ignore those */ if (self->requested == 0) @@ -195,6 +193,8 @@ update_status_progress_and_estimating (FlatpakProgress *self) return; } + buf = g_string_new (""); + /* The heuristic here goes as follows: * - While fetching metadata, grow up to 5% * - Download goes up to 97% diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c index f577d6e0..90036c6d 100644 --- a/common/flatpak-utils.c +++ b/common/flatpak-utils.c @@ -2302,7 +2302,9 @@ flatpak_parse_repofile (const char *remote_name, collection_id = g_key_file_get_string (keyfile, source_group, FLATPAK_REPO_DEPLOY_COLLECTION_ID_KEY, NULL); - if (collection_id == NULL || *collection_id == '\0') + if (collection_id != NULL && *collection_id == '\0') + g_clear_pointer (&collection_id, g_free); + if (collection_id == NULL) collection_id = g_key_file_get_string (keyfile, source_group, FLATPAK_REPO_COLLECTION_ID_KEY, NULL); if (collection_id != NULL)