summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2020-09-04 18:16:19 +0200
committerMax Kellermann <max@musicpd.org>2020-09-04 18:17:24 +0200
commitdb8b419b8c3aa738efb3fa7b5de7b2894ced6cde (patch)
tree2407865c6eedcf66bea38420d40c3fc47712b1f1
parent990f631cbcdab3a611fb4d90fbf8a06f5c5c1183 (diff)
archive/iso9660: free iso9660_stat_t as early as possible
-rw-r--r--src/archive/plugins/Iso9660ArchivePlugin.cxx24
1 files 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<Iso9660> iso;
- iso9660_stat_t *statbuf;
+ const lsn_t lsn;
public:
Iso9660InputStream(const std::shared_ptr<Iso9660> &_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<Iso9660InputStream>(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",