diff options
author | rubidium <rubidium@openttd.org> | 2011-02-11 21:30:26 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-02-11 21:30:26 +0000 |
commit | 7de823b1bde0f48fd5bd235ffdcc032eda5cdd1b (patch) | |
tree | 44f69fdc51781f63364893f74b27c1077b1504da /src | |
parent | 296af357411e20ccaacf4c78dc0f36da1fae0a65 (diff) | |
download | openttd-7de823b1bde0f48fd5bd235ffdcc032eda5cdd1b.tar.xz |
(svn r22062) -Fix: memory leak when saving fails mid-way
Diffstat (limited to 'src')
-rw-r--r-- | src/saveload/saveload.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index ae759f4d1..62c0ff9f5 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -2012,6 +2012,12 @@ struct ZlibSaveFilter : SaveFilter { 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 @@ struct ZlibSaveFilter : SaveFilter { { this->WriteLoop(NULL, 0, Z_FINISH); this->chain->Finish(); - deflateEnd(&this->z); } }; @@ -2134,6 +2139,12 @@ struct LZMASaveFilter : SaveFilter { 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 @@ struct LZMASaveFilter : SaveFilter { { this->WriteLoop(NULL, 0, LZMA_FINISH); this->chain->Finish(); - lzma_end(&this->lzma); } }; |