Mercurial > hg > openttd
changeset 17322:b242b2078674 draft
(svn r22062) -Fix: memory leak when saving fails mid-way
author | rubidium <rubidium@openttd.org> |
---|---|
date | Fri, 11 Feb 2011 21:30:26 +0000 |
parents | e23208bb065b |
children | 1f1269635087 |
files | src/saveload/saveload.cpp |
diffstat | 1 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -2012,6 +2012,12 @@ if (deflateInit(&this->z, compression_level) != Z_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor"); } + /** Clean up what we allocated. */ + ~ZlibSaveFilter() + { + deflateEnd(&this->z); + } + /** * Helper loop for writing the data. * @param p The bytes to write. @@ -2056,7 +2062,6 @@ { this->WriteLoop(NULL, 0, Z_FINISH); this->chain->Finish(); - deflateEnd(&this->z); } }; @@ -2134,6 +2139,12 @@ if (lzma_easy_encoder(&this->lzma, compression_level, LZMA_CHECK_CRC32) != LZMA_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor"); } + /** Clean up what we allocated. */ + ~LZMASaveFilter() + { + lzma_end(&this->lzma); + } + /** * Helper loop for writing the data. * @param p The bytes to write. @@ -2170,7 +2181,6 @@ { this->WriteLoop(NULL, 0, LZMA_FINISH); this->chain->Finish(); - lzma_end(&this->lzma); } };