diff --git a/desmume/src/NDSSystem.c b/desmume/src/NDSSystem.c index 8ba5f1e21..7377596a8 100644 --- a/desmume/src/NDSSystem.c +++ b/desmume/src/NDSSystem.c @@ -202,7 +202,12 @@ int NDS_LoadROM(const char *filename, int bmtype, u32 bmsize) type = ROM_DSGBA; file = reader->Init(filename); - if (!file) return -1 ; + + if (!file) + { + free(noext); + return -1; + } size = reader->Size(file); if(type == ROM_DSGBA) @@ -226,6 +231,7 @@ int NDS_LoadROM(const char *filename, int bmtype, u32 bmsize) if ((data = (u8*)malloc(mask + 1)) == NULL) { reader->DeInit(file); + free(noext); return -1; } @@ -255,7 +261,10 @@ int NDS_LoadROM(const char *filename, int bmtype, u32 bmsize) if (strlen(noext)>= strlen(DSGBA_EXTENSTION)) strncpy(noext + strlen(noext) - strlen(DSGBA_EXTENSTION), ".sav",strlen(DSGBA_EXTENSTION)+1); else - return -1 ; + { + free(noext); + return -1; + } } else { @@ -263,7 +272,10 @@ int NDS_LoadROM(const char *filename, int bmtype, u32 bmsize) if (strlen(noext)>=4) strncpy(noext + strlen(noext) - 4, ".sav",5); else - return -1 ; + { + free(noext); + return -1; + } } mc_realloc(&MMU.bupmem, bmtype, bmsize); diff --git a/desmume/src/windows/main.c b/desmume/src/windows/main.c index 32d265b87..7fd2d511a 100644 --- a/desmume/src/windows/main.c +++ b/desmume/src/windows/main.c @@ -499,7 +499,11 @@ int WINAPI WinMain (HINSTANCE hThisInstance, SPU_SetVolume(sndvolume); runthread = CreateThread(NULL, 0, run, NULL, 0, &threadID); - + + // Make sure any quotes from lpszArgument are removed + if (lpszArgument[0] == '\"') + sscanf(lpszArgument, "\"%[^\"]\"", lpszArgument); + if(LoadROM(lpszArgument)) { EnableMenuItem(menu, IDM_EXEC, MF_GRAYED);