archive/iso9660: free iso9660_stat_t as early as possible

This commit is contained in:
Max Kellermann 2020-09-04 18:16:19 +02:00
parent 990f631cbc
commit db8b419b8c

View File

@ -142,23 +142,21 @@ Iso9660ArchiveFile::Visit(ArchiveVisitor &visitor)
class Iso9660InputStream final : public InputStream { class Iso9660InputStream final : public InputStream {
std::shared_ptr<Iso9660> iso; std::shared_ptr<Iso9660> iso;
iso9660_stat_t *statbuf; const lsn_t lsn;
public: public:
Iso9660InputStream(const std::shared_ptr<Iso9660> &_iso, Iso9660InputStream(const std::shared_ptr<Iso9660> &_iso,
const char *_uri, const char *_uri,
Mutex &_mutex, Mutex &_mutex,
iso9660_stat_t *_statbuf) lsn_t _lsn, offset_type _size)
:InputStream(_uri, _mutex), :InputStream(_uri, _mutex),
iso(_iso), statbuf(_statbuf) { iso(_iso),
size = statbuf->size; lsn(_lsn)
{
size = _size;
SetReady(); SetReady();
} }
~Iso9660InputStream() {
free(statbuf);
}
/* virtual methods from InputStream */ /* virtual methods from InputStream */
bool IsEOF() noexcept override; bool IsEOF() noexcept override;
size_t Read(void *ptr, size_t size) 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", throw FormatRuntimeError("not found in the ISO file: %s",
pathname); pathname);
const lsn_t lsn = statbuf->lsn;
const offset_type size = statbuf->size;
free(statbuf);
return std::make_unique<Iso9660InputStream>(iso, pathname, mutex, return std::make_unique<Iso9660InputStream>(iso, pathname, mutex,
statbuf); lsn, size);
} }
size_t size_t
@ -184,7 +186,7 @@ Iso9660InputStream::Read(void *ptr, size_t read_size)
int readed = 0; int readed = 0;
int no_blocks, cur_block; int no_blocks, cur_block;
size_t left_bytes = statbuf->size - offset; size_t left_bytes = size - offset;
if (left_bytes < read_size) { if (left_bytes < read_size) {
no_blocks = CEILING(left_bytes, ISO_BLOCKSIZE); no_blocks = CEILING(left_bytes, ISO_BLOCKSIZE);
@ -197,7 +199,7 @@ Iso9660InputStream::Read(void *ptr, size_t read_size)
cur_block = offset / ISO_BLOCKSIZE; 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) if (readed != no_blocks * ISO_BLOCKSIZE)
throw FormatRuntimeError("error reading ISO file at lsn %lu", throw FormatRuntimeError("error reading ISO file at lsn %lu",