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