From db8b419b8c3aa738efb3fa7b5de7b2894ced6cde Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 4 Sep 2020 18:16:19 +0200 Subject: [PATCH] archive/iso9660: free iso9660_stat_t as early as possible --- src/archive/plugins/Iso9660ArchivePlugin.cxx | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/archive/plugins/Iso9660ArchivePlugin.cxx b/src/archive/plugins/Iso9660ArchivePlugin.cxx index 6cb307bd4..6314fb025 100644 --- a/src/archive/plugins/Iso9660ArchivePlugin.cxx +++ b/src/archive/plugins/Iso9660ArchivePlugin.cxx @@ -142,23 +142,21 @@ Iso9660ArchiveFile::Visit(ArchiveVisitor &visitor) class Iso9660InputStream final : public InputStream { std::shared_ptr iso; - iso9660_stat_t *statbuf; + const lsn_t lsn; public: Iso9660InputStream(const std::shared_ptr &_iso, const char *_uri, Mutex &_mutex, - iso9660_stat_t *_statbuf) + lsn_t _lsn, offset_type _size) :InputStream(_uri, _mutex), - iso(_iso), statbuf(_statbuf) { - size = statbuf->size; + iso(_iso), + lsn(_lsn) + { + size = _size; SetReady(); } - ~Iso9660InputStream() { - free(statbuf); - } - /* virtual methods from InputStream */ bool IsEOF() noexcept override; size_t Read(void *ptr, size_t size) override; @@ -173,8 +171,12 @@ Iso9660ArchiveFile::OpenStream(const char *pathname, throw FormatRuntimeError("not found in the ISO file: %s", pathname); + const lsn_t lsn = statbuf->lsn; + const offset_type size = statbuf->size; + free(statbuf); + return std::make_unique(iso, pathname, mutex, - statbuf); + lsn, size); } size_t @@ -184,7 +186,7 @@ Iso9660InputStream::Read(void *ptr, size_t read_size) int readed = 0; int no_blocks, cur_block; - size_t left_bytes = statbuf->size - offset; + size_t left_bytes = size - offset; if (left_bytes < read_size) { no_blocks = CEILING(left_bytes, ISO_BLOCKSIZE); @@ -197,7 +199,7 @@ Iso9660InputStream::Read(void *ptr, size_t read_size) cur_block = offset / ISO_BLOCKSIZE; - readed = iso->SeekRead(ptr, statbuf->lsn + cur_block, no_blocks); + readed = iso->SeekRead(ptr, lsn + cur_block, no_blocks); if (readed != no_blocks * ISO_BLOCKSIZE) throw FormatRuntimeError("error reading ISO file at lsn %lu",