https://bugs.kde.org/show_bug.cgi?id=432726
Bug ID: 432726 Summary: Memory leak on "Could not set device mode to 3" error when trying to open unwritable archive Product: frameworks-karchive Version: unspecified Platform: Debian stable OS: Linux Status: REPORTED Severity: normal Priority: NOR Component: general Assignee: fa...@kde.org Reporter: vin...@gmail.com CC: kdelibs-b...@kde.org Target Milestone: --- With Qt 5.15.2 (and 5.13.2), KArchive master on Debian 10 Buster amd64, running this code: ``` #include <QDebug> #include <QIODevice> #include <QString> #include <KZip> int main() { KZip zip{QStringLiteral("/unwritable_file.zip")}; if (!zip.open(QIODevice::ReadWrite)) { qCritical() << zip.errorString(); } } ``` Produces this memory leak: ``` 561 (16 direct, 545 indirect) bytes in 1 blocks are definitely lost in loss record 16 of 17 in main in /home/vincas/code/opensource/karchive_bug/karchive_leak/main.cpp:11 1: operator new(unsigned long) in ./coregrind/m_replacemalloc/vg_replace_malloc.c:334 2: KArchive::createDevice(QFlags<QIODevice::OpenModeFlag>) in /home/vincas/code/opensource/karchive_bug/karchive.git/src/karchive.cpp:198 3: KArchive::open(QFlags<QIODevice::OpenModeFlag>) in /home/vincas/code/opensource/karchive_bug/karchive.git/src/karchive.cpp:144 4: main in /home/vincas/code/opensource/karchive_bug/karchive_leak/main.cpp:11 ``` Looks like QFile is not deleted in this error case, after being create here: https://invent.kde.org/frameworks/karchive/-/blob/940558bcebee041d66bd75ec2d0839c281b31356/src/karchive.cpp#L198 Originally detected using leak sanitizer with GCC. Looping 100000 times, the application leaks ~70MB (instead of 4MB usage at the start, before loop). As a sidenote, maybe it would we worth refactoring to use std::unique_ptr..? -- You are receiving this mail because: You are watching all bug changes.