don't always free pFile from ~RageFileObjInflate
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "global.h"
|
||||
#include "RageFileDriverDeflate.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageUtil.h"
|
||||
|
||||
#if defined(_WINDOWS) || defined(_XBOX)
|
||||
#include "zlib/zlib.h"
|
||||
@@ -20,15 +21,14 @@
|
||||
|
||||
RageFileObjInflate::RageFileObjInflate( RageFileBasic *pFile, int iUncompressedSize )
|
||||
{
|
||||
m_bFileOwned = false;
|
||||
m_pFile = pFile;
|
||||
decomp_buf_avail = 0;
|
||||
m_pInflate = new z_stream;
|
||||
memset( m_pInflate, 0, sizeof(z_stream) );
|
||||
|
||||
m_iUncompressedSize = iUncompressedSize;
|
||||
|
||||
m_pInflate->zalloc = Z_NULL;
|
||||
m_pInflate->zfree = Z_NULL;
|
||||
|
||||
int err = inflateInit2( m_pInflate, -MAX_WBITS );
|
||||
if( err == Z_MEM_ERROR )
|
||||
RageException::Throw( "inflateInit2( %i ): out of memory", -MAX_WBITS );
|
||||
@@ -48,6 +48,7 @@ RageFileObjInflate::RageFileObjInflate( const RageFileObjInflate &cpy ):
|
||||
ASSERT( 0 );
|
||||
/*
|
||||
m_pFile = cpy.m_pFile->Copy();
|
||||
m_bFileOwned = true;
|
||||
m_pInflate = new z_stream;
|
||||
inflateCopy( m_pInflate, const_cast<z_stream*>(cpy.m_pInflate) );
|
||||
|
||||
@@ -68,7 +69,8 @@ RageFileBasic *RageFileObjInflate::Copy() const
|
||||
|
||||
RageFileObjInflate::~RageFileObjInflate()
|
||||
{
|
||||
delete m_pFile;
|
||||
if( m_bFileOwned )
|
||||
delete m_pFile;
|
||||
|
||||
int err = inflateEnd( m_pInflate );
|
||||
if( err != Z_OK )
|
||||
|
||||
@@ -10,7 +10,8 @@ typedef struct z_stream_s z_stream;
|
||||
class RageFileObjInflate: public RageFileObj
|
||||
{
|
||||
public:
|
||||
/* pFile will be freed. */
|
||||
/* By default, pFile will not be freed. To implement GetFileSize(), the
|
||||
* container format must store the file size. */
|
||||
RageFileObjInflate( RageFileBasic *pFile, int iUncompressedSize );
|
||||
RageFileObjInflate( const RageFileObjInflate &cpy );
|
||||
~RageFileObjInflate();
|
||||
@@ -20,10 +21,13 @@ public:
|
||||
int GetFileSize() const { return m_iUncompressedSize; }
|
||||
RageFileBasic *Copy() const;
|
||||
|
||||
void DeleteFileWhenFinished() { m_bFileOwned = true; }
|
||||
|
||||
private:
|
||||
int m_iUncompressedSize;
|
||||
RageFileBasic *m_pFile;
|
||||
int m_iFilePos;
|
||||
bool m_bFileOwned;
|
||||
|
||||
z_stream *m_pInflate;
|
||||
enum { INBUFSIZE = 1024*4 };
|
||||
|
||||
@@ -372,7 +372,11 @@ RageFileBasic *RageFileDriverZip::Open( const CString &path, int mode, int &err
|
||||
case STORED:
|
||||
return pFile;
|
||||
case DEFLATED:
|
||||
return new RageFileObjInflate( pFile, info->uncompr_size );
|
||||
{
|
||||
RageFileObjInflate *pInflate = new RageFileObjInflate( pFile, info->uncompr_size );
|
||||
pInflate->DeleteFileWhenFinished();
|
||||
return pInflate;
|
||||
}
|
||||
default:
|
||||
/* unknown compression method */
|
||||
ASSERT( 0 );
|
||||
|
||||
Reference in New Issue
Block a user