fix leak of cloned entry (#4487)

This commit is contained in:
Rachel Powers 2025-12-13 18:52:49 -07:00 committed by GitHub
commit c33d104dc3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,6 +23,7 @@
#include <archive_entry.h>
#include <QDir>
#include <QFileInfo>
#include <memory>
namespace MMCZip {
QStringList ArchiveReader::getFiles()
@ -130,8 +131,10 @@ static int copy_data(struct archive* ar, struct archive* aw, bool notBlock = fal
bool ArchiveReader::File::writeFile(archive* out, QString targetFileName, bool notBlock)
{
auto entry = m_entry;
std::unique_ptr<archive_entry, decltype(&archive_entry_free)> entryClone(nullptr, &archive_entry_free);
if (!targetFileName.isEmpty()) {
entry = archive_entry_clone(m_entry);
entryClone.reset(archive_entry_clone(m_entry));
entry = entryClone.get();
auto nameUtf8 = targetFileName.toUtf8();
archive_entry_set_pathname(entry, nameUtf8.constData());
}