From 48bf24b41e0222039e343dca175dcecd768c7e0c Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 20 Sep 2017 18:57:47 +0200 Subject: XEEN: Change SavesManager to use a map of pointers to MemoryWriteStreamDynamic Our implementation of HashMap does not allow value types without a zero-argument constructor. --- engines/xeen/saves.cpp | 13 ++++++++----- engines/xeen/saves.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/engines/xeen/saves.cpp b/engines/xeen/saves.cpp index 4df4b3727c..f7d93d1dc4 100644 --- a/engines/xeen/saves.cpp +++ b/engines/xeen/saves.cpp @@ -37,10 +37,10 @@ void OutFile::finalize() { uint16 id = BaseCCArchive::convertNameToId(_filename); if (!_vm->_saves->_newData.contains(id)) - _vm->_saves->_newData[id] = Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES); + _vm->_saves->_newData[id] = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES); - Common::MemoryWriteStreamDynamic &out = _vm->_saves->_newData[id]; - out.write(getData(), size()); + Common::MemoryWriteStreamDynamic *out = _vm->_saves->_newData[id]; + out->write(getData(), size()); } /*------------------------------------------------------------------------*/ @@ -54,6 +54,9 @@ SavesManager::SavesManager(XeenEngine *vm, Party &party) : } SavesManager::~SavesManager() { + for (Common::HashMap::iterator it = _newData.begin(); it != _newData.end(); it++) { + delete (*it)._value; + } delete[] _data; } @@ -86,8 +89,8 @@ Common::SeekableReadStream *SavesManager::createReadStreamForMember(const Common // save manager, then return that new resource uint16 id = BaseCCArchive::convertNameToId(name); if (_newData.contains(id)) { - Common::MemoryWriteStreamDynamic stream = _newData[id]; - return new Common::MemoryReadStream(stream.getData(), stream.size()); + Common::MemoryWriteStreamDynamic *stream = _newData[id]; + return new Common::MemoryReadStream(stream->getData(), stream->size()); } // Retrieve the resource from the loaded savefile diff --git a/engines/xeen/saves.h b/engines/xeen/saves.h index 2571c46600..404dee00a7 100644 --- a/engines/xeen/saves.h +++ b/engines/xeen/saves.h @@ -60,7 +60,7 @@ private: XeenEngine *_vm; Party &_party; byte *_data; - Common::HashMap _newData; + Common::HashMap _newData; void load(Common::SeekableReadStream *stream); public: -- cgit v1.2.3 From bc531e3ebf6e2c3a67a79be4439f32b4989ce808 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 20 Sep 2017 19:27:03 +0200 Subject: XEEN: Change OutFile not to subclass MemoryWriteStreamDynamic Also fix leaking the MemoryWriteStreamDynamic buffer storage --- engines/xeen/saves.cpp | 14 ++++++++++++-- engines/xeen/saves.h | 7 ++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/engines/xeen/saves.cpp b/engines/xeen/saves.cpp index f7d93d1dc4..f9a26b1d6b 100644 --- a/engines/xeen/saves.cpp +++ b/engines/xeen/saves.cpp @@ -30,7 +30,17 @@ namespace Xeen { OutFile::OutFile(XeenEngine *vm, const Common::String filename) : - _vm(vm), _filename(filename) { + _vm(vm), + _filename(filename), + _backingStream(DisposeAfterUse::YES) { +} + +uint32 OutFile::write(const void *dataPtr, uint32 dataSize) { + return _backingStream.write(dataPtr, dataSize); +} + +int32 OutFile::pos() const { + return _backingStream.pos(); } void OutFile::finalize() { @@ -40,7 +50,7 @@ void OutFile::finalize() { _vm->_saves->_newData[id] = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES); Common::MemoryWriteStreamDynamic *out = _vm->_saves->_newData[id]; - out->write(getData(), size()); + out->write(_backingStream.getData(), _backingStream.size()); } /*------------------------------------------------------------------------*/ diff --git a/engines/xeen/saves.h b/engines/xeen/saves.h index 404dee00a7..9c161c838c 100644 --- a/engines/xeen/saves.h +++ b/engines/xeen/saves.h @@ -44,14 +44,19 @@ struct XeenSavegameHeader { class XeenEngine; class SavesManager; -class OutFile : public Common::MemoryWriteStreamDynamic { +class OutFile : public Common::WriteStream { private: XeenEngine *_vm; Common::String _filename; + Common::MemoryWriteStreamDynamic _backingStream; public: OutFile(XeenEngine *vm, const Common::String filename); void finalize(); + + uint32 write(const void *dataPtr, uint32 dataSize) override; + + int32 pos() const override; }; class SavesManager: public BaseCCArchive { -- cgit v1.2.3 From 2832332e74ecd0d166631dd516a98ffcde5b65b3 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 20 Sep 2017 19:12:04 +0200 Subject: NETWORKING: Changed NetworkReadStream not to subclass MemoryReadWriteStream Also fix the MemoryReadWriteStream managed buffer being leaked. Fixes #9718. --- backends/networking/curl/networkreadstream.cpp | 23 +++++++------ backends/networking/curl/networkreadstream.h | 46 +++++++++++++++----------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/backends/networking/curl/networkreadstream.cpp b/backends/networking/curl/networkreadstream.cpp index e4fc5492b5..d3859cebc2 100644 --- a/backends/networking/curl/networkreadstream.cpp +++ b/backends/networking/curl/networkreadstream.cpp @@ -29,35 +29,35 @@ namespace Networking { -static size_t curlDataCallback(char *d, size_t n, size_t l, void *p) { +size_t NetworkReadStream::curlDataCallback(char *d, size_t n, size_t l, void *p) { NetworkReadStream *stream = (NetworkReadStream *)p; if (stream) - return stream->write(d, n * l); + return stream->_backingStream.write(d, n * l); return 0; } -static size_t curlReadDataCallback(char *d, size_t n, size_t l, void *p) { +size_t NetworkReadStream::curlReadDataCallback(char *d, size_t n, size_t l, void *p) { NetworkReadStream *stream = (NetworkReadStream *)p; if (stream) return stream->fillWithSendingContents(d, n * l); return 0; } -static size_t curlHeadersCallback(char *d, size_t n, size_t l, void *p) { +size_t NetworkReadStream::curlHeadersCallback(char *d, size_t n, size_t l, void *p) { NetworkReadStream *stream = (NetworkReadStream *)p; if (stream) return stream->addResponseHeaders(d, n * l); return 0; } -static int curlProgressCallback(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { +int NetworkReadStream::curlProgressCallback(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { NetworkReadStream *stream = (NetworkReadStream *)p; if (stream) stream->setProgress(dlnow, dltotal); return 0; } -static int curlProgressCallbackOlder(void *p, double dltotal, double dlnow, double ultotal, double ulnow) { +int NetworkReadStream::curlProgressCallbackOlder(void *p, double dltotal, double dlnow, double ultotal, double ulnow) { // for libcurl older than 7.32.0 (CURLOPT_PROGRESSFUNCTION) return curlProgressCallback(p, (curl_off_t)dltotal, (curl_off_t)dlnow, (curl_off_t)ultotal, (curl_off_t)ulnow); } @@ -178,15 +178,18 @@ void NetworkReadStream::init(const char *url, curl_slist *headersList, Common::H ConnMan.registerEasyHandle(_easy); } -NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, Common::String postFields, bool uploading, bool usingPatch) { +NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, Common::String postFields, bool uploading, bool usingPatch) : + _backingStream(DisposeAfterUse::YES) { init(url, headersList, (const byte *)postFields.c_str(), postFields.size(), uploading, usingPatch, false); } -NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, Common::HashMap formFields, Common::HashMap formFiles) { +NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, Common::HashMap formFields, Common::HashMap formFiles) : + _backingStream(DisposeAfterUse::YES) { init(url, headersList, formFields, formFiles); } -NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post) { +NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post) : + _backingStream(DisposeAfterUse::YES) { init(url, headersList, buffer, bufferSize, uploading, usingPatch, post); } @@ -201,7 +204,7 @@ bool NetworkReadStream::eos() const { } uint32 NetworkReadStream::read(void *dataPtr, uint32 dataSize) { - uint32 actuallyRead = MemoryReadWriteStream::read(dataPtr, dataSize); + uint32 actuallyRead = _backingStream.read(dataPtr, dataSize); if (actuallyRead == 0) { if (_requestComplete) diff --git a/backends/networking/curl/networkreadstream.h b/backends/networking/curl/networkreadstream.h index 8e59429a0a..c0ed5ee1c6 100644 --- a/backends/networking/curl/networkreadstream.h +++ b/backends/networking/curl/networkreadstream.h @@ -34,8 +34,9 @@ struct curl_slist; namespace Networking { -class NetworkReadStream: public Common::MemoryReadWriteStream { +class NetworkReadStream: public Common::ReadStream { CURL *_easy; + Common::MemoryReadWriteStream _backingStream; bool _eos, _requestComplete; const byte *_sendingContentsBuffer; uint32 _sendingContentsSize; @@ -46,6 +47,30 @@ class NetworkReadStream: public Common::MemoryReadWriteStream { void init(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post); void init(const char *url, curl_slist *headersList, Common::HashMap formFields, Common::HashMap formFiles); + /** + * Fills the passed buffer with _sendingContentsBuffer contents. + * It works similarly to read(), expect it's not for reading + * Stream's contents, but for sending our own data to the server. + * + * @returns how many bytes were actually read (filled in) + */ + uint32 fillWithSendingContents(char *bufferToFill, uint32 maxSize); + + /** + * Remembers headers returned to CURL in server's response. + * + * @returns how many bytes were actually read + */ + uint32 addResponseHeaders(char *buffer, uint32 bufferSize); + + /** Used in curl progress callback to pass current downloaded/total values. */ + void setProgress(uint64 downloaded, uint64 total); + + static size_t curlDataCallback(char *d, size_t n, size_t l, void *p); + static size_t curlReadDataCallback(char *d, size_t n, size_t l, void *p); + static size_t curlHeadersCallback(char *d, size_t n, size_t l, void *p); + static int curlProgressCallback(void *p, long dltotal, long dlnow, long ultotal, long ulnow); + static int curlProgressCallbackOlder(void *p, double dltotal, double dlnow, double ultotal, double ulnow); public: /** Send , using POST by default. */ NetworkReadStream(const char *url, curl_slist *headersList, Common::String postFields, bool uploading = false, bool usingPatch = false); @@ -115,27 +140,8 @@ public: */ Common::String responseHeaders() const; - /** - * Fills the passed buffer with _sendingContentsBuffer contents. - * It works similarly to read(), expect it's not for reading - * Stream's contents, but for sending our own data to the server. - * - * @returns how many bytes were actually read (filled in) - */ - uint32 fillWithSendingContents(char *bufferToFill, uint32 maxSize); - - /** - * Remembers headers returned to CURL in server's response. - * - * @returns how many bytes were actually read - */ - uint32 addResponseHeaders(char *buffer, uint32 bufferSize); - /** Returns a number in range [0, 1], where 1 is "complete". */ double getProgress() const; - - /** Used in curl progress callback to pass current downloaded/total values. */ - void setProgress(uint64 downloaded, uint64 total); }; } // End of namespace Networking -- cgit v1.2.3 From ab1243277ab18ce54720dc734c48520f01274ad9 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 20 Sep 2017 19:14:12 +0200 Subject: DM: Fix leaking the save thumbnail MemoryWriteStreamDynamic buffer --- engines/dm/eventman.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/dm/eventman.cpp b/engines/dm/eventman.cpp index 622a7d5e1f..3859fc90b2 100644 --- a/engines/dm/eventman.cpp +++ b/engines/dm/eventman.cpp @@ -782,7 +782,7 @@ void EventManager::processCommandQueue() { delete _vm->_saveThumbnail; _vm->_saveThumbnail = nullptr; } else if (!_vm->_saveThumbnail) { - _vm->_saveThumbnail = new Common::MemoryWriteStreamDynamic(); + _vm->_saveThumbnail = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES); Graphics::saveThumbnail(*_vm->_saveThumbnail); } -- cgit v1.2.3 From 9facbdecda3f15d2fd9889294ecd4e550050c0a3 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 20 Sep 2017 19:15:56 +0200 Subject: FULLPIPE: Fix leaking the save MemoryWriteStreamDynamic buffer --- engines/fullpipe/statesaver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/fullpipe/statesaver.cpp b/engines/fullpipe/statesaver.cpp index 7fb56f0479..5eb08fe213 100644 --- a/engines/fullpipe/statesaver.cpp +++ b/engines/fullpipe/statesaver.cpp @@ -55,7 +55,7 @@ bool GameLoader::writeSavegame(Scene *sc, const char *fname) { header.updateCounter = _updateCounter; header.unkField = 1; - Common::MemoryWriteStreamDynamic stream; + Common::MemoryWriteStreamDynamic stream(DisposeAfterUse::YES); MfcArchive *archive = new MfcArchive(&stream); -- cgit v1.2.3 From 382df4a7c5a15938009dac71e8d0a0fa1559ea54 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 20 Sep 2017 19:16:55 +0200 Subject: GNAP: Fix leaking the save thumbnail MemoryWriteStreamDynamic buffer --- engines/gnap/menu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/gnap/menu.cpp b/engines/gnap/menu.cpp index 2bfe7300df..9606273b4c 100644 --- a/engines/gnap/menu.cpp +++ b/engines/gnap/menu.cpp @@ -211,7 +211,7 @@ void GnapEngine::runMenu() { _menuDone = false; delete _tempThumbnail; - _tempThumbnail = new Common::MemoryWriteStreamDynamic; + _tempThumbnail = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES); Graphics::saveThumbnail(*_tempThumbnail); createMenuSprite(); -- cgit v1.2.3 From c3bff7f25a24c549885b8e402fb499b0dd48b9cd Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 20 Sep 2017 19:18:44 +0200 Subject: SWORD1: Fix leaking the save thumbnail MemoryWriteStreamDynamic buffer --- engines/sword1/control.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp index fbc3f6af4a..0c53430ba3 100644 --- a/engines/sword1/control.cpp +++ b/engines/sword1/control.cpp @@ -303,7 +303,7 @@ static int volToBalance(int volL, int volR) { uint8 Control::runPanel() { // Make a thumbnail of the screen before displaying the menu in case we want to save // the game from the menu. - _tempThumbnail = new Common::MemoryWriteStreamDynamic; + _tempThumbnail = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES); Graphics::saveThumbnail(*_tempThumbnail); _panelShown = true; -- cgit v1.2.3 From 9c2cfee4e53f5e678d37b33cdcb354782932b10c Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 20 Sep 2017 19:20:14 +0200 Subject: SWORD25: Fix leaking the save thumbnail MemoryWriteStreamDynamic --- engines/sword25/gfx/screenshot.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index eeaece97f2..c86a2fe1d5 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -113,11 +113,11 @@ Common::SeekableReadStream *Screenshot::createThumbnail(Graphics::Surface *data) } // Create a PNG representation of the thumbnail data - Common::MemoryWriteStreamDynamic *stream = new Common::MemoryWriteStreamDynamic(); - saveToFile(&thumbnail, stream); + Common::MemoryWriteStreamDynamic stream(DisposeAfterUse::NO); + saveToFile(&thumbnail, &stream); // Output a MemoryReadStream that encompasses the written data - Common::SeekableReadStream *result = new Common::MemoryReadStream(stream->getData(), stream->size(), + Common::SeekableReadStream *result = new Common::MemoryReadStream(stream.getData(), stream.size(), DisposeAfterUse::YES); return result; } -- cgit v1.2.3 From ddac55699d69be8c02b724b413fb92d1a93b7257 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 20 Sep 2017 19:21:42 +0200 Subject: SWORD25: Fix leaking the lua state MemoryWriteStreamDynamic buffer --- engines/sword25/script/luascript.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/sword25/script/luascript.cpp b/engines/sword25/script/luascript.cpp index 3aca6676ac..1a83fc9c82 100644 --- a/engines/sword25/script/luascript.cpp +++ b/engines/sword25/script/luascript.cpp @@ -395,7 +395,7 @@ bool LuaScriptEngine::persist(OutputPersistenceBlock &writer) { lua_getglobal(_state, "_G"); // Lua persists and stores the data in a WriteStream - Common::MemoryWriteStreamDynamic writeStream; + Common::MemoryWriteStreamDynamic writeStream(DisposeAfterUse::YES); Lua::persistLua(_state, &writeStream); // Persistenzdaten in den Writer schreiben. -- cgit v1.2.3 From 1b3cc08b75c56a06cfa90edaf1b0da181d40ddcc Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 20 Sep 2017 19:29:05 +0200 Subject: ZVISION: Fix leaking save / thumbnail MemoryWriteStreamDynamic buffers --- engines/zvision/file/save_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/zvision/file/save_manager.cpp b/engines/zvision/file/save_manager.cpp index 8a78e988b3..4259937a3b 100644 --- a/engines/zvision/file/save_manager.cpp +++ b/engines/zvision/file/save_manager.cpp @@ -273,11 +273,11 @@ Common::SeekableReadStream *SaveManager::getSlotFile(uint slot) { void SaveManager::prepareSaveBuffer() { delete _tempThumbnail; - _tempThumbnail = new Common::MemoryWriteStreamDynamic; + _tempThumbnail = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES); Graphics::saveThumbnail(*_tempThumbnail); delete _tempSave; - _tempSave = new Common::MemoryWriteStreamDynamic; + _tempSave = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES); _engine->getScriptManager()->serialize(_tempSave); } -- cgit v1.2.3 From 3eb82462e772832a902ba336b680e2a961339ee1 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 20 Sep 2017 19:01:51 +0200 Subject: ALL: Specify the DisposeAfterUse constructor argument for dynamic memory write streams --- audio/decoders/quicktime.cpp | 2 +- audio/midiparser_qt.cpp | 2 +- engines/agi/sound_midi.cpp | 2 +- engines/pegasus/ai/ai_area.cpp | 2 +- engines/scumm/saveload.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/audio/decoders/quicktime.cpp b/audio/decoders/quicktime.cpp index b8eccb664b..4b0d5e078f 100644 --- a/audio/decoders/quicktime.cpp +++ b/audio/decoders/quicktime.cpp @@ -344,7 +344,7 @@ bool QuickTimeAudioDecoder::QuickTimeAudioTrack::isOldDemuxing() const { AudioStream *QuickTimeAudioDecoder::QuickTimeAudioTrack::readAudioChunk(uint chunk) { AudioSampleDesc *entry = (AudioSampleDesc *)_parentTrack->sampleDescs[0]; - Common::MemoryWriteStreamDynamic *wStream = new Common::MemoryWriteStreamDynamic(); + Common::MemoryWriteStreamDynamic *wStream = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::NO); _decoder->_fd->seek(_parentTrack->chunkOffsets[chunk]); diff --git a/audio/midiparser_qt.cpp b/audio/midiparser_qt.cpp index 3078be9186..8821dbfaa8 100644 --- a/audio/midiparser_qt.cpp +++ b/audio/midiparser_qt.cpp @@ -455,7 +455,7 @@ void MidiParser_QT::initCommon() { byte *MidiParser_QT::readWholeTrack(Common::QuickTimeParser::Track *track, uint32 &trackSize) { // This just goes through all chunks and appends them together - Common::MemoryWriteStreamDynamic output; + Common::MemoryWriteStreamDynamic output(DisposeAfterUse::NO); uint32 curSample = 0; // Read in the note request data first diff --git a/engines/agi/sound_midi.cpp b/engines/agi/sound_midi.cpp index 6998df6862..97dcc0d98b 100644 --- a/engines/agi/sound_midi.cpp +++ b/engines/agi/sound_midi.cpp @@ -169,7 +169,7 @@ static uint32 convertSND2MIDI(byte *snddata, byte **data) { int n; double ll; - Common::MemoryWriteStreamDynamic st; + Common::MemoryWriteStreamDynamic st(DisposeAfterUse::NO); ll = log10(pow(2.0, 1.0 / 12.0)); diff --git a/engines/pegasus/ai/ai_area.cpp b/engines/pegasus/ai/ai_area.cpp index c078d5e80e..58698e6c77 100644 --- a/engines/pegasus/ai/ai_area.cpp +++ b/engines/pegasus/ai/ai_area.cpp @@ -78,7 +78,7 @@ void AIArea::saveAIState() { delete vm->_aiSaveStream; - Common::MemoryWriteStreamDynamic out; + Common::MemoryWriteStreamDynamic out(DisposeAfterUse::NO); writeAIRules(&out); vm->_aiSaveStream = new Common::MemoryReadStream(out.getData(), out.size(), DisposeAfterUse::YES); diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 0ab36d1a96..06d564648b 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -228,7 +228,7 @@ void ScummEngine_v4::prepareSavegame() { _savePreparedSavegame = NULL; // store headerless savegame in a compressed memory stream - memStream = new Common::MemoryWriteStreamDynamic(); + memStream = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::NO); writeStream = Common::wrapCompressedWriteStream(memStream); if (saveState(writeStream, false)) { // we have to finalize the compression-stream first, otherwise the internal -- cgit v1.2.3 From be67f0d8bfb4148e014931cce63b52e84ed95ee6 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 20 Sep 2017 19:42:09 +0200 Subject: COMMON: Remove DisposeAfterUse default value from dynamic write memory streams The default value was DisposeAfterUse::NO, which made it very easy to accidentally leak memory by omitting to specify a value. --- common/memstream.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/memstream.h b/common/memstream.h index 0338d35378..f6bf990208 100644 --- a/common/memstream.h +++ b/common/memstream.h @@ -184,7 +184,7 @@ protected: _size = new_len; } public: - MemoryWriteStreamDynamic(DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : _capacity(0), _size(0), _ptr(0), _data(0), _pos(0), _disposeMemory(disposeMemory) {} + explicit MemoryWriteStreamDynamic(DisposeAfterUse::Flag disposeMemory) : _capacity(0), _size(0), _ptr(0), _data(0), _pos(0), _disposeMemory(disposeMemory) {} ~MemoryWriteStreamDynamic() { if (_disposeMemory) @@ -247,7 +247,7 @@ private: } } public: - MemoryReadWriteStream(DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : _capacity(0), _size(0), _data(0), _writePos(0), _readPos(0), _pos(0), _length(0), _disposeMemory(disposeMemory), _eos(false) {} + explicit MemoryReadWriteStream(DisposeAfterUse::Flag disposeMemory) : _capacity(0), _size(0), _data(0), _writePos(0), _readPos(0), _pos(0), _length(0), _disposeMemory(disposeMemory), _eos(false) {} ~MemoryReadWriteStream() { if (_disposeMemory) -- cgit v1.2.3