From d0c948394d4342dd0ea2b068f0b72e998dc8a784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= Date: Fri, 19 Jul 2024 14:20:33 +0200 Subject: [PATCH] Unify freeing of `target->zck_dl` to a single place Apart from these two places the `zck_dl` is leaking through other code paths. Handle it and stuff it contains in a single place. --- librepo/downloader.c | 4 ---- librepo/downloadtarget.c | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/librepo/downloader.c b/librepo/downloader.c index 7208a4079..5b610632a 100644 --- a/librepo/downloader.c +++ b/librepo/downloader.c @@ -1357,8 +1357,6 @@ check_zck(LrTarget *target, GError **err) if(cks_good == 1) { // All checksums good g_debug("%s: File is complete", __func__); - if(target->target->zck_dl) - zck_dl_free(&(target->target->zck_dl)); target->zck_state = LR_ZCK_DL_FINISHED; return TRUE; } @@ -1378,8 +1376,6 @@ check_zck(LrTarget *target, GError **err) } if(cks_good == 1) { // All checksums good - if(target->target->zck_dl) - zck_dl_free(&(target->target->zck_dl)); target->zck_state = LR_ZCK_DL_FINISHED; return TRUE; } diff --git a/librepo/downloadtarget.c b/librepo/downloadtarget.c index 6825aef32..e502968af 100644 --- a/librepo/downloadtarget.c +++ b/librepo/downloadtarget.c @@ -134,6 +134,26 @@ lr_downloadtarget_free(LrDownloadTarget *target) if (!target) return; + #ifdef WITH_ZCHUNK + if (target->zck_dl) { + zckCtx *old_zck = zck_dl_get_zck(target->zck_dl); + if (old_zck) { + zck_free(&old_zck); + } + + zckRange *old_range = zck_dl_get_range(target->zck_dl); + if(old_range) { + zck_range_free(&old_range); + } + + zck_dl_free(&target->zck_dl); + } + #endif /* WITH_ZCHUNK */ + + if(target->range) { + free(target->range); + } + g_slist_free_full(target->checksums, (GDestroyNotify) lr_downloadtargetchecksum_free); g_string_chunk_free(target->chunk);