Fixes for some file handles and memory leaks.

This commit is contained in:
aquanull 2018-04-04 18:28:42 +08:00
parent 5a1e6c552a
commit 2d81852e81
3 changed files with 16 additions and 4 deletions

View File

@ -126,7 +126,10 @@ void UpdateReplayCommentsSubs(const char * fname) {
MOVIE_INFO info;
FCEUFILE *fp = FCEU_fopen(fname,0,"rb",0);
fp->stream = fp->stream->memwrap();
EMUFILE *tmp = fp->stream->memwrap();
if (tmp != fp->stream)
delete fp->stream;
fp->stream = tmp;
bool scanok = FCEUI_MovieGetInfo(fp, info, true);
delete fp;
@ -151,8 +154,11 @@ void UpdateReplayDialog(HWND hwndDlg)
{
MOVIE_INFO info;
FCEUFILE* fp = FCEU_fopen(fn,0,"rb",0);
fp->stream = fp->stream->memwrap();
FCEUFILE *fp = FCEU_fopen(fn,0,"rb",0);
EMUFILE *tmp = fp->stream->memwrap();
if (tmp != fp->stream)
delete fp->stream;
fp->stream = tmp;
bool isarchive = FCEU_isFileInArchive(fn);
bool ismovie = FCEUI_MovieGetInfo(fp, info, false);
delete fp;

View File

@ -86,6 +86,7 @@ void EMUFILE_FILE::truncate(s32 length)
#else
ftruncate(fileno(fp),length);
#endif
// this is probably wrong if mode is "wb"
fclose(fp);
fp = NULL;
open(fname.c_str(),mode);

View File

@ -284,11 +284,16 @@ FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext
{
//if the archive contained no files, try to open it the old fashioned way
EMUFILE_FILE* fp = FCEUD_UTF8_fstream(fileToOpen,mode);
if(!fp || (fp->get_fp() == NULL))
if(!fp)
return 0;
if (fp->get_fp() == NULL)
{
//fp is new'ed so it has to be deleted
delete fp;
return 0;
}
//try to read a zip file
{
fceufp = TryUnzip(fileToOpen);