From a43fec486837d797aa6fbf195c60c055ecbcdf10 Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 7 Mar 2024 00:29:43 +0100 Subject: [PATCH] Fix memory leak in archiving utilities --- libpkg/parser/utils.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libpkg/parser/utils.cpp b/libpkg/parser/utils.cpp index 2a99612..dfb1991 100644 --- a/libpkg/parser/utils.cpp +++ b/libpkg/parser/utils.cpp @@ -74,7 +74,7 @@ void walkThroughArchiveInternal(struct archive *ar, const string &archiveName, c } if (directoryHandler(std::string_view(filePath, dirEnd))) { - return; + goto free; } continue; } @@ -101,7 +101,7 @@ void walkThroughArchiveInternal(struct archive *ar, const string &archiveName, c if (entryType == AE_IFLNK) { if (fileHandler(std::string_view(filePath, static_cast(dirEnd - filePath)), ArchiveFile(fileName, std::string(archive_entry_symlink_utf8(entry)), ArchiveFileType::Link, creationTime, modificationTime))) { - return; + goto free; } continue; } @@ -128,11 +128,12 @@ void walkThroughArchiveInternal(struct archive *ar, const string &archiveName, c // move it to results if (fileHandler(std::string_view(filePath, static_cast(dirEnd - filePath)), ArchiveFile(fileName, std::move(fileContent), ArchiveFileType::Regular, creationTime, modificationTime))) { - return; + goto free; } } // free resources used by libarchive +free: archive_entry_free(entry); int returnCode = archive_read_free(ar); if (returnCode != ARCHIVE_OK) {