diff --git a/Source/Core/DiscIO/CompressedBlob.cpp b/Source/Core/DiscIO/CompressedBlob.cpp index c3b79baf1c..74427c95a1 100644 --- a/Source/Core/DiscIO/CompressedBlob.cpp +++ b/Source/Core/DiscIO/CompressedBlob.cpp @@ -11,7 +11,9 @@ #include #include #include +#include #include +#include #include #include "Common/CommonTypes.h" @@ -303,21 +305,18 @@ bool DecompressBlobToFile(const std::string& infile, const std::string& outfile, return false; } - CompressedBlobReader* reader = CompressedBlobReader::Create(infile); + std::unique_ptr reader(CompressedBlobReader::Create(infile)); if (!reader) return false; File::IOFile f(outfile, "wb"); if (!f) - { - delete reader; return false; - } const CompressedBlobHeader &header = reader->GetHeader(); static const size_t BUFFER_BLOCKS = 32; size_t buffer_size = header.block_size * BUFFER_BLOCKS; - u8* buffer = new u8[buffer_size]; + std::vector buffer(buffer_size); u32 num_buffers = header.num_blocks / BUFFER_BLOCKS; int progress_monitor = std::max(1, num_buffers / 100); bool was_cancelled = false; @@ -330,12 +329,10 @@ bool DecompressBlobToFile(const std::string& infile, const std::string& outfile, if (was_cancelled) break; } - reader->Read(i * buffer_size, buffer_size, buffer); - f.WriteBytes(buffer, buffer_size); + reader->Read(i * buffer_size, buffer_size, buffer.data()); + f.WriteBytes(buffer.data(), buffer_size); } - delete[] buffer; - if (was_cancelled) { // Remove the incomplete output file. @@ -347,8 +344,6 @@ bool DecompressBlobToFile(const std::string& infile, const std::string& outfile, f.Resize(header.data_size); } - delete reader; - return true; } diff --git a/Source/Core/DiscIO/VolumeDirectory.cpp b/Source/Core/DiscIO/VolumeDirectory.cpp index 3a9e75f1d2..f2163773f4 100644 --- a/Source/Core/DiscIO/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/VolumeDirectory.cpp @@ -112,7 +112,7 @@ bool CVolumeDirectory::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const _dbg_assert_(DVDINTERFACE, fileIter->first <= _Offset); u64 fileOffset = _Offset - fileIter->first; - PlainFileReader* reader = PlainFileReader::Create(fileIter->second); + std::unique_ptr reader(PlainFileReader::Create(fileIter->second)); if (reader == nullptr) return false; @@ -139,8 +139,6 @@ bool CVolumeDirectory::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const _dbg_assert_(DVDINTERFACE, fileIter->first >= _Offset); PadToAddress(fileIter->first, _Offset, _Length, _pBuffer); } - - delete reader; } return true;