fix minor memleaks: a few bytes per screenshot, and a harmless "leak"

if IMG_LoadTyped_RW fails
This commit is contained in:
Glenn Maynard
2004-05-02 02:15:01 +00:00
parent d3f461220a
commit 82595ecfe1
2 changed files with 5 additions and 3 deletions
+1
View File
@@ -662,6 +662,7 @@ bool RageDisplay::SaveScreenshot( CString sPath, GraphicsFileFormat format )
return false;
}
SDL_RWclose( rw );
SDL_FreeRW( rw );
SDL_FreeSurface( surface );
+4 -3
View File
@@ -1158,8 +1158,6 @@ int RWRageFile_Close(struct SDL_RWops *context)
SDL_RWops *OpenRWops( const CString &sPath, bool Write )
{
SDL_RWops *rw = SDL_AllocRW();
RageFile *f = new RageFile;
if( !f->Open(sPath, Write? RageFile::WRITE:RageFile::READ) )
{
@@ -1168,6 +1166,8 @@ SDL_RWops *OpenRWops( const CString &sPath, bool Write )
return NULL;
}
SDL_RWops *rw = SDL_AllocRW();
ASSERT( rw );
rw->hidden.unknown.data1 = f;
rw->seek = RWRageFile_Seek;
rw->read = RWRageFile_Read;
@@ -1183,7 +1183,8 @@ SDL_Surface *SDL_LoadImage( const CString &sPath )
if( rw == NULL )
return NULL;
SDL_Surface *ret = IMG_LoadTyped_RW( rw, true, (char *) GetExtension(sPath).c_str() );
SDL_Surface *ret = IMG_LoadTyped_RW( rw, false, (char *) GetExtension(sPath).c_str() );
SDL_RWclose( rw );
SDL_FreeRW( rw );
return ret;