diff --git a/components/bsa/tes4bsa_file.cpp b/components/bsa/tes4bsa_file.cpp index 5c36061d5c..2b04f2f1c4 100644 --- a/components/bsa/tes4bsa_file.cpp +++ b/components/bsa/tes4bsa_file.cpp @@ -353,13 +353,12 @@ Files::IStreamPtr TES4BSAFile::getFile(const FileRecord& fileRecord) { inputStreamBuf.push(boost::iostreams::zlib_decompressor()); inputStreamBuf.push(*fileStream); - std::shared_ptr > bufferVec = std::make_shared>(uncompressedSize); - Bsa::MemoryInputStream* result = new MemoryInputStream(uncompressedSize); + std::shared_ptr memoryStreamPtr = std::make_shared(uncompressedSize); - boost::iostreams::basic_array_sink sr(result->getRawData(), uncompressedSize); + boost::iostreams::basic_array_sink sr(memoryStreamPtr->getRawData(), uncompressedSize); boost::iostreams::copy(inputStreamBuf, sr); - std::istream* pPtr = (std::istream*) result; - return std::shared_ptr(pPtr); + + return std::shared_ptr(memoryStreamPtr, (std::istream*)memoryStreamPtr.get()); } return Files::openConstrainedFileStream(mFilename.c_str(), fileRecord.offset, fileRecord.size);