diff options
author | David Turner | 2011-01-28 02:56:07 +0000 |
---|---|---|
committer | David Turner | 2011-01-28 02:56:07 +0000 |
commit | f7e1ed37628973d5dc515fdf4e2ce27fbc3e1e26 (patch) | |
tree | 49f65750495585c0cb4e0f4e07aa13952ec1b0a6 | |
parent | 44035c303337832dba27688ff54bac9643c9f942 (diff) | |
download | scummvm-rg350-f7e1ed37628973d5dc515fdf4e2ce27fbc3e1e26.tar.gz scummvm-rg350-f7e1ed37628973d5dc515fdf4e2ce27fbc3e1e26.tar.bz2 scummvm-rg350-f7e1ed37628973d5dc515fdf4e2ce27fbc3e1e26.zip |
COMMON: Fixed memory leakage in unarj readHeader().
This manifested in Drascula.
svn-id: r55582
-rw-r--r-- | common/unarj.cpp | 32 | ||||
-rw-r--r-- | common/unarj.h | 6 |
2 files changed, 11 insertions, 27 deletions
diff --git a/common/unarj.cpp b/common/unarj.cpp index 89acf51cb5..2c4225f393 100644 --- a/common/unarj.cpp +++ b/common/unarj.cpp @@ -39,7 +39,6 @@ namespace Common { - #define ARJ_UCHAR_MAX 255 #define ARJ_CHAR_BIT 8 @@ -65,7 +64,6 @@ namespace Common { #define ARJ_CTABLESIZE 4096 #define ARJ_PTABLESIZE 256 - // these struct represents a file inside an Arj archive struct ArjHeader { int32 pos; @@ -150,7 +148,6 @@ private: uint16 _blocksize; }; - #define HEADER_ID 0xEA60 #define HEADER_ID_HI 0xEA #define HEADER_ID_LO 0x60 @@ -164,9 +161,7 @@ private: #define PBIT 5 #define TBIT 5 -// // Source for CRC32::init, CRC32::checksum : crc32.c -// class CRC32 { static uint32 _table[256]; static bool _initialized; @@ -207,11 +202,7 @@ public: bool CRC32::_initialized = false; uint32 CRC32::_table[256]; - -// // Source for findHeader and readHeader: arj_arcv.c -// - int32 findHeader(SeekableReadStream &stream) { long end_pos, tmp_pos; int id; @@ -320,13 +311,7 @@ ArjHeader *readHeader(SeekableReadStream &stream) { return head; } - - - -// // Source for init_getbits: arj_file.c (decode_start_stub) -// - void ArjDecoder::init_getbits() { _bitbuf = 0; _bytebuf = 0; @@ -334,10 +319,7 @@ void ArjDecoder::init_getbits() { fillbuf(ARJ_CHAR_BIT * 2); } -// // Source for fillbuf, getbits: decode.c -// - void ArjDecoder::fillbuf(int n) { while (_bitcount < n) { _bitbuf = (_bitbuf << _bitcount) | (_bytebuf >> (8 - _bitcount)); @@ -364,12 +346,8 @@ uint16 ArjDecoder::getbits(int n) { return rc; } - - -// // Huffman decode routines // Source: decode.c -// // Creates a table for decoding void ArjDecoder::make_table(int nchar, byte *bitlen, int tablebits, uint16 *table, int tablesize) { @@ -718,7 +696,6 @@ void ArjDecoder::decode_f(int32 origsize) { typedef HashMap<String, ArjHeader*, IgnoreCase_Hash, IgnoreCase_EqualTo> ArjHeadersMap; class ArjArchive : public Common::Archive { - ArjHeadersMap _headers; Common::String _arjFilename; @@ -748,11 +725,13 @@ ArjArchive::ArjArchive(const String &filename) : _arjFilename(filename) { return; } + ArjHeader *header = NULL; + arjFile.seek(firstHeaderOffset, SEEK_SET); - if (readHeader(arjFile) == NULL) + if ((header = readHeader(arjFile)) == NULL) return; + delete header; - ArjHeader *header; while ((header = readHeader(arjFile)) != NULL) { _headers[header->filename] = header; arjFile.seek(header->compSize, SEEK_CUR); @@ -762,13 +741,13 @@ ArjArchive::ArjArchive(const String &filename) : _arjFilename(filename) { } ArjArchive::~ArjArchive() { + debug(0, "ArjArchive Destructor Called"); ArjHeadersMap::iterator it = _headers.begin(); for ( ; it != _headers.end(); ++it) { delete it->_value; } } - bool ArjArchive::hasFile(const String &name) { return _headers.contains(name); } @@ -803,7 +782,6 @@ SeekableReadStream *ArjArchive::createReadStreamForMember(const String &name) co archiveFile.open(_arjFilename); archiveFile.seek(hdr->pos, SEEK_SET); - // TODO: It would be good if ArjFile could decompress files in a streaming // mode, so it would not need to pre-allocate the entire output. byte *uncompressedData = (byte *)malloc(hdr->origSize); diff --git a/common/unarj.h b/common/unarj.h index 38450fa40a..fa7d388542 100644 --- a/common/unarj.h +++ b/common/unarj.h @@ -23,6 +23,12 @@ * */ +/** + * @file + * ARJ decompressor used in engines: + * - drascula + */ + #ifndef COMMON_UNARJ_H #define COMMON_UNARJ_H |