[Scummvm-cvs-logs] SF.net SVN: scummvm:[55582] scummvm/trunk/common

tdhs at users.sourceforge.net tdhs at users.sourceforge.net
Fri Jan 28 03:56:07 CET 2011


Revision: 55582
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55582&view=rev
Author:   tdhs
Date:     2011-01-28 02:56:07 +0000 (Fri, 28 Jan 2011)

Log Message:
-----------
COMMON: Fixed memory leakage in unarj readHeader().

This manifested in Drascula.

Modified Paths:
--------------
    scummvm/trunk/common/unarj.cpp
    scummvm/trunk/common/unarj.h

Modified: scummvm/trunk/common/unarj.cpp
===================================================================
--- scummvm/trunk/common/unarj.cpp	2011-01-28 02:30:25 UTC (rev 55581)
+++ scummvm/trunk/common/unarj.cpp	2011-01-28 02:56:07 UTC (rev 55582)
@@ -39,7 +39,6 @@
 
 namespace Common {
 
-
 #define ARJ_UCHAR_MAX 255
 #define ARJ_CHAR_BIT 8
 
@@ -65,7 +64,6 @@
 #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 @@
 	uint16 _blocksize;
 };
 
-
 #define HEADER_ID     0xEA60
 #define HEADER_ID_HI    0xEA
 #define HEADER_ID_LO    0x60
@@ -164,9 +161,7 @@
 #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 @@
 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 @@
 	return head;
 }
 
-
-
-
-//
 // Source for init_getbits: arj_file.c (decode_start_stub)
-//
-
 void ArjDecoder::init_getbits() {
 	_bitbuf = 0;
 	_bytebuf = 0;
@@ -334,10 +319,7 @@
 	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 @@
 	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 @@
 typedef HashMap<String, ArjHeader*, IgnoreCase_Hash, IgnoreCase_EqualTo> ArjHeadersMap;
 
 class ArjArchive : public Common::Archive {
-
 	ArjHeadersMap _headers;
 	Common::String _arjFilename;
 
@@ -748,11 +725,13 @@
 		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() {
+	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 @@
 	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);

Modified: scummvm/trunk/common/unarj.h
===================================================================
--- scummvm/trunk/common/unarj.h	2011-01-28 02:30:25 UTC (rev 55581)
+++ scummvm/trunk/common/unarj.h	2011-01-28 02:56:07 UTC (rev 55582)
@@ -23,6 +23,12 @@
  *
  */
 
+/**
+ * @file
+ * ARJ decompressor used in engines:
+ * - drascula
+ */
+
 #ifndef COMMON_UNARJ_H
 #define COMMON_UNARJ_H
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list