From 6f2dcdc2d929d3202e0c70faa43dfe89fc23b6f8 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 11 Aug 2018 23:12:12 +0200 Subject: [PATCH] Fix leaking memory or file handles in StreamDataBlock descendants StreamDataBlock needs a virtual d'tor since it is supposed to be subclassed but the d'tor will be called on the base type. The leaking file handles were observed by invoking the tests with strace, eg.: strace -e trace=file,close ./tagparser_tests --- abstractattachment.cpp | 9 ++++++++- abstractattachment.h | 1 + tests/overallmkv.cpp | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/abstractattachment.cpp b/abstractattachment.cpp index f31ea2e..c4aa292 100644 --- a/abstractattachment.cpp +++ b/abstractattachment.cpp @@ -57,6 +57,13 @@ StreamDataBlock::StreamDataBlock(const std::function &stream, } } +/*! + * \brief Discards buffered data. + */ +StreamDataBlock::~StreamDataBlock() +{ +} + /*! * \brief Buffers the data block. Buffered data can be accessed via buffer(). */ @@ -95,7 +102,7 @@ void StreamDataBlock::copyTo(ostream &stream) const * \throws Throws ios_base::failure when an IO error occurs. */ FileDataBlock::FileDataBlock(const string &path, Diagnostics &diag) - : m_fileInfo(new MediaFileInfo) + : m_fileInfo(make_unique()) { m_fileInfo->setPath(path); m_fileInfo->open(true); diff --git a/abstractattachment.h b/abstractattachment.h index 57b4beb..2f94802 100644 --- a/abstractattachment.h +++ b/abstractattachment.h @@ -17,6 +17,7 @@ public: StreamDataBlock(const std::function &stream, std::istream::off_type startOffset = 0, std::ios_base::seekdir startDir = std::ios_base::beg, std::istream::off_type endOffset = 0, std::ios_base::seekdir endDir = std::ios_base::end); + virtual ~StreamDataBlock(); std::istream &stream() const; std::istream::pos_type startOffset() const; diff --git a/tests/overallmkv.cpp b/tests/overallmkv.cpp index 6bbfe5f..ba51cb5 100644 --- a/tests/overallmkv.cpp +++ b/tests/overallmkv.cpp @@ -620,7 +620,7 @@ void OverallTests::setMkvTestMetaData() newTag->setValue(KnownField::PartNumber, m_testPartNumber); newTag->setValue(KnownField::TotalParts, m_testTotalParts); // assign an attachment - AbstractAttachment *attachment = container->createAttachment(); + AbstractAttachment *const attachment = container->createAttachment(); CPPUNIT_ASSERT_MESSAGE("create attachment", attachment); attachment->setFile(TestUtilities::testFilePath("matroska_wave1/logo3_256x256.png"), m_diag); attachment->setMimeType("image/png");