From 82595ecfe1a310aa78691579a21ffe956c96be9e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 2 May 2004 02:15:01 +0000 Subject: [PATCH] fix minor memleaks: a few bytes per screenshot, and a harmless "leak" if IMG_LoadTyped_RW fails --- stepmania/src/RageDisplay.cpp | 1 + stepmania/src/SDL_utils.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/stepmania/src/RageDisplay.cpp b/stepmania/src/RageDisplay.cpp index d9b7adbbc8..56594f41df 100644 --- a/stepmania/src/RageDisplay.cpp +++ b/stepmania/src/RageDisplay.cpp @@ -662,6 +662,7 @@ bool RageDisplay::SaveScreenshot( CString sPath, GraphicsFileFormat format ) return false; } + SDL_RWclose( rw ); SDL_FreeRW( rw ); SDL_FreeSurface( surface ); diff --git a/stepmania/src/SDL_utils.cpp b/stepmania/src/SDL_utils.cpp index fc5e1a608c..912d6eecc1 100644 --- a/stepmania/src/SDL_utils.cpp +++ b/stepmania/src/SDL_utils.cpp @@ -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;