diff --git a/src/fileimpl.cpp b/src/fileimpl.cpp index fea3c777..882f9ae5 100644 --- a/src/fileimpl.cpp +++ b/src/fileimpl.cpp @@ -188,7 +188,7 @@ class Grouping {} #endif - FileImpl::FileImpl(std::shared_ptr _zimFile) + FileImpl::FileImpl(std::shared_ptr _zimFile) try : zimFile(_zimFile), zimReader(makeFileReader(zimFile)), direntReader(new DirentReader(zimReader)), @@ -265,6 +265,9 @@ class Grouping m_byTitleDirentLookup.reset(new ByTitleDirentLookup(mp_titleDirentAccessor.get())); readMimeTypes(); + } catch (...) { + getClusterCache().drop_all([=](const std::tuple& key) {return std::get<0>(key) == this;}); + throw; } FileImpl::~FileImpl() { diff --git a/test/archive.cpp b/test/archive.cpp index c91f16b4..81960b7c 100644 --- a/test/archive.cpp +++ b/test/archive.cpp @@ -50,6 +50,9 @@ class ZimArchive: public testing::Test { zim::set_cluster_cache_max_size(CLUSTER_CACHE_SIZE); ASSERT_EQ(zim::get_cluster_cache_current_size(), 0); } + void TearDown() override { + ASSERT_EQ(zim::get_cluster_cache_current_size(), 0); + } }; using TestContextImpl = std::vector >; @@ -691,7 +694,8 @@ class CapturedStderr #define EXPECT_BROKEN_ZIMFILE(ZIMPATH, EXPECTED_STDERROR_TEXT) \ CapturedStderr stderror; \ EXPECT_FALSE(zim::validate(ZIMPATH, checksToRun)); \ - EXPECT_EQ(EXPECTED_STDERROR_TEXT, std::string(stderror)) << ZIMPATH; + EXPECT_EQ(EXPECTED_STDERROR_TEXT, std::string(stderror)) << ZIMPATH; \ + ASSERT_EQ(zim::get_cluster_cache_current_size(), 0); #define TEST_BROKEN_ZIM_NAME(ZIMNAME, EXPECTED) \ for(auto& testfile: getDataFilePath(ZIMNAME)) {EXPECT_BROKEN_ZIMFILE(testfile.path, EXPECTED)}