From 7e453d5b97685db696752af85d7e3201417c905f Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Sun, 13 May 2012 17:25:26 +0000 Subject: [PATCH] -all free should be safe now :P --- source/channel/MD5.c | 6 ++-- source/channel/banner.cpp | 14 +++++--- source/channel/channel_launcher.c | 16 ++++----- source/channel/channels.cpp | 33 +++++++++-------- source/channel/nand.cpp | 46 +++++++++++++++++------- source/devicemounter/PartitionHandle.cpp | 23 ++++++++---- source/gc/fileOps.c | 7 +++- source/gc/gc.c | 4 +++ source/gecko/gecko.c | 23 ++++++------ source/gecko/wifi_gecko.c | 16 --------- source/gecko/wifi_gecko.h | 1 - source/gui/WiiMovie.cpp | 9 ++--- source/gui/gcvid.cpp | 3 +- source/gui/pngu.c | 8 +++-- source/loader/cios.cpp | 23 ++++++------ source/loader/frag.c | 30 ++++++++++------ source/loader/fs.c | 7 ++-- source/loader/gc_disc.cpp | 25 +++++++++---- source/menu/menu.cpp | 17 ++++----- source/menu/menu_about.cpp | 2 +- source/menu/menu_download.cpp | 2 +- 21 files changed, 184 insertions(+), 131 deletions(-) diff --git a/source/channel/MD5.c b/source/channel/MD5.c index f88c0d30..357e4a1c 100644 --- a/source/channel/MD5.c +++ b/source/channel/MD5.c @@ -566,9 +566,8 @@ unsigned char * MD5fromFile(unsigned char *dst, const char *src) else blksize = 1048576; - unsigned char * buffer = MEM2_alloc(blksize); - - if(!!buffer) + unsigned char * buffer = MEM2_alloc(blksize); + if(buffer == NULL) { //no memory fclose(file); @@ -579,7 +578,6 @@ unsigned char * MD5fromFile(unsigned char *dst, const char *src) { read = fread(buffer, 1, blksize, file); (void)auth_md5SumCtx( ctx, buffer, read ); /* Pass only one block. */ - } while(read > 0); fclose(file); diff --git a/source/channel/banner.cpp b/source/channel/banner.cpp index 207038c4..86d65d74 100644 --- a/source/channel/banner.cpp +++ b/source/channel/banner.cpp @@ -82,7 +82,8 @@ Banner::Banner(u8 *bnr, u64 title) Banner::~Banner() { - MEM2_free(opening); + if(opening != NULL) + MEM2_free(opening); } bool Banner::IsValid() @@ -152,10 +153,11 @@ Banner * Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly) { u32 size = 0; - buf = ISFS_GetFile((u8 *) appname, &size, imetOnly ? sizeof(IMET) + IMET_OFFSET : 0); + buf = ISFS_GetFile((u8 *)appname, &size, imetOnly ? sizeof(IMET) + IMET_OFFSET : 0); if (size == 0) { - free(buf); + if(buf != NULL) + MEM2_free(buf); return NULL; } } @@ -171,12 +173,14 @@ Banner * Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly) size = ftell(fp); fseek(fp, 0, SEEK_SET); } - + buf = MEM2_alloc(size); + if(!buf) + return NULL; fread(buf, size, 1, fp); fclose(fp); } return new Banner((u8 *)buf, title); -} \ No newline at end of file +} diff --git a/source/channel/channel_launcher.c b/source/channel/channel_launcher.c index 3f20c638..914a37cc 100644 --- a/source/channel/channel_launcher.c +++ b/source/channel/channel_launcher.c @@ -43,7 +43,7 @@ s32 BootChannel(u8 *data, u64 chantitle, u8 vidMode, bool vipatch, bool countryS Identify(chantitle, &ios); entryPoint = LoadChannel(data); - free(data); + MEM2_free(data); /* Select an appropriate video mode */ GXRModeObj * vmode = __Disc_SelectVMode(vidMode, chantitle); @@ -243,8 +243,8 @@ bool Identify(u64 titleid, u32 *ios) if (certBuffer == NULL || certSize == 0) { gprintf("Reading certs...Failed!\n"); - free(tmdBuffer); - free(tikBuffer); + MEM2_free(tmdBuffer); + MEM2_free(tikBuffer); return false; } @@ -271,9 +271,9 @@ bool Identify(u64 titleid, u32 *ios) } } - free(tmdBuffer); - free(tikBuffer); - free(certBuffer); + MEM2_free(tmdBuffer); + MEM2_free(tikBuffer); + MEM2_free(certBuffer); return ret < 0 ? false : true; } @@ -297,10 +297,10 @@ u8 * GetDol(u64 title, u32 bootcontent) if (decompressLZ77content(data, contentSize, &decompressed, &size) < 0) { gprintf("Decompression failed\n"); - free(data); + MEM2_free(data); return NULL; } - free(data); + MEM2_free(data); data = decompressed; } return data; diff --git a/source/channel/channels.cpp b/source/channel/channels.cpp index d324acf4..5d79d6fd 100644 --- a/source/channel/channels.cpp +++ b/source/channel/channels.cpp @@ -92,12 +92,14 @@ u8 Channels::GetRequestedIOS(u64 title) sprintf(tmd, "/title/%08x/%08x/content/title.tmd", TITLE_UPPER(title), TITLE_LOWER(title)); u32 size; - u8 *titleTMD = (u8 *) ISFS_GetFile((u8 *) &tmd, &size, -1); + u8 *titleTMD = (u8 *)ISFS_GetFile((u8 *) &tmd, &size, -1); + if(titleTMD == NULL) + return 0; if(size > 0x18B) IOS = titleTMD[0x18B]; - free(titleTMD); + MEM2_free(titleTMD); return IOS; } @@ -113,20 +115,18 @@ u64* Channels::GetChannelList(u32* count) if (ES_GetNumTitles(&countall) < 0 || !countall) return NULL; u64* titles = (u64*)MEM2_alloc(countall * sizeof(u64)); - if (!titles) return NULL; + if (!titles) + return NULL; if(ES_GetTitles(titles, countall) < 0) { - free(titles); + MEM2_free(titles); return NULL; } u64* channels = (u64*)MEM2_alloc(countall * sizeof(u64)); if (!channels) - { - free(titles); return NULL; - } *count = 0; for (u32 i = 0; i < countall; i++) @@ -138,13 +138,12 @@ u64* Channels::GetChannelList(u32* count) if (TITLE_LOWER(titles[i]) == RF_NEWS_CHANNEL || // skip region free news and forecast channel TITLE_LOWER(titles[i]) == RF_FORECAST_CHANNEL) continue; - channels[(*count)++] = titles[i]; } } - free(titles); + MEM2_free(titles); - return (u64*)MEM2_realloc(channels, *count * sizeof(u64)); + return(u64*)MEM2_realloc(channels, *count * sizeof(u64)); } bool Channels::GetAppNameFromTmd(u64 title, char* app, bool dol, u32* bootcontent) @@ -156,11 +155,13 @@ bool Channels::GetAppNameFromTmd(u64 title, char* app, bool dol, u32* bootconten u32 size; u8 *data = ISFS_GetFile((u8 *) &tmd, &size, -1); - if (data == NULL || size < 0x208) return ret; + if (data == NULL || size < 0x208) + return ret; - _tmd * tmd_file = (_tmd *) SIGNATURE_PAYLOAD((u32 *)data); + _tmd *tmd_file = (_tmd *)SIGNATURE_PAYLOAD((u32 *)data); u16 i; for(i = 0; i < tmd_file->num_contents; ++i) + { if(tmd_file->contents[i].index == (dol ? tmd_file->boot_index : 0)) { *bootcontent = tmd_file->contents[i].cid; @@ -168,8 +169,9 @@ bool Channels::GetAppNameFromTmd(u64 title, char* app, bool dol, u32* bootconten ret = true; break; } + } - free(data); + MEM2_free(data); return ret; } @@ -224,7 +226,8 @@ void Channels::Search(u32 channelType, string lang) { u32 count; u64* list = GetChannelList(&count); - if (!list) return; + if (list == NULL) + return; int language = lang.size() == 0 ? CONF_GetLanguage() : GetLanguage(lang.c_str()); @@ -245,7 +248,7 @@ void Channels::Search(u32 channelType, string lang) } } - free(list); + MEM2_free(list); } wchar_t * Channels::GetName(int index) diff --git a/source/channel/nand.cpp b/source/channel/nand.cpp index 996ea76a..7b443aa6 100644 --- a/source/channel/nand.cpp +++ b/source/channel/nand.cpp @@ -234,19 +234,27 @@ void Nand::__GetNameList(const char *source, namelist **entries, int *count) { u32 i, j, k, l; u32 numentries = 0; - char *names; + char *names = NULL; char curentry[ISFS_MAXPATH]; char entrypath[ISFS_MAXPATH]; s32 ret = ISFS_ReadDir(source, NULL, &numentries); names = (char *)MEM2_alloc((ISFS_MAXPATH) * numentries); + if(names == NULL) + return; + ret = ISFS_ReadDir(source, names, &numentries); *count = numentries; - if(*entries) + if(*entries != NULL) + { MEM2_free(*entries); + *entries = NULL; + } - *entries = (namelist *)MEM2_alloc(sizeof(namelist)*numentries); + *entries = (namelist *)MEM2_alloc(sizeof(namelist) * numentries); + if(*entries == NULL) + return; for(i = 0, k = 0; i < numentries; i++) { @@ -273,6 +281,9 @@ s32 Nand::__configread(void) { confbuffer = (u8 *)MEM2_alloc(0x4000); txtbuffer = (char *)MEM2_alloc(0x100); + if(confbuffer == NULL || txtbuffer == NULL) + return -1; + cfg_hdr = (config_header *)NULL; FILE *f = fopen(cfgpath, "rb"); @@ -322,16 +333,16 @@ s32 Nand::__configwrite(void) fwrite(txtbuffer, 1, 0x100, f); gprintf("setting.txt written to: \"%s\"\n", settxtpath); fclose(f); - } + } configloaded = configloaded ? false : true; if(!tbdec && !configloaded) - return 1; + return 1; } } - free(confbuffer); - free(txtbuffer); - return 0; + MEM2_free(confbuffer); + MEM2_free(txtbuffer); + return 0; } u32 Nand::__configsetbyte(const char *item, u8 val) @@ -512,6 +523,9 @@ s32 Nand::__FlashNandFile(const char *source, const char *dest) } u8 *buffer = (u8 *)MEM2_alloc(BLOCK); + if(buffer == NULL) + return -1; + u32 toread = fsize; while(toread > 0) { @@ -572,6 +586,9 @@ s32 Nand::__DumpNandFile(const char *source, const char *dest) } fstats *status = (fstats *)MEM2_alloc(sizeof(fstats)); + if(status == NULL) + return -1; + s32 ret = ISFS_GetFileStats(fd, status); if (ret < 0) { @@ -605,6 +622,9 @@ s32 Nand::__DumpNandFile(const char *source, const char *dest) gprintf("Dumping: %s (%ukb)...", source, (status->file_length / 0x400)+1); u8 *buffer = (u8 *)MEM2_alloc(BLOCK); + if(buffer == NULL) + return -1; + u32 toread = status->file_length; while(toread > 0) { @@ -740,7 +760,7 @@ s32 Nand::__DumpNandFolder(const char *source, const char *dest) __DumpNandFolder(nsource, dest); } } - free(names); + MEM2_free(names); return 0; } @@ -777,9 +797,9 @@ void Nand::CreatePath(const char *path, ...) gprintf("Folder \"%s\" exists\n", folder); closedir(d); } + free(folder); } va_end(args); - free(folder); } void Nand::CreateTitleTMD(const char *path, dir_discHdr *hdr) @@ -792,7 +812,7 @@ void Nand::CreateTitleTMD(const char *path, dir_discHdr *hdr) u32 tmd_size = wbfs_extract_file(disc, (char *) "TMD", (void **)&titleTMD); WBFS_CloseDisc(disc); - if(!titleTMD) + if(titleTMD == NULL) return; u32 highTID = *(u32*)(titleTMD+0x18c); @@ -810,7 +830,7 @@ void Nand::CreateTitleTMD(const char *path, dir_discHdr *hdr) struct stat filestat; if (stat(nandpath, &filestat) == 0) { - free(titleTMD); + MEM2_free(titleTMD); gprintf("%s Exists!\n", nandpath); return; } @@ -826,7 +846,7 @@ void Nand::CreateTitleTMD(const char *path, dir_discHdr *hdr) else gprintf("Creating title TMD: %s failed (%i)\n", nandpath, file); - free(titleTMD); + MEM2_free(titleTMD); } s32 Nand::FlashToNAND(const char *source, const char *dest, dump_callback_t i_dumper, void *i_data) diff --git a/source/devicemounter/PartitionHandle.cpp b/source/devicemounter/PartitionHandle.cpp index 60453065..61fc7d9d 100644 --- a/source/devicemounter/PartitionHandle.cpp +++ b/source/devicemounter/PartitionHandle.cpp @@ -178,7 +178,8 @@ void PartitionHandle::UnMount(int pos) int PartitionHandle::FindPartitions() { MASTER_BOOT_RECORD *mbr = (MASTER_BOOT_RECORD *)MEM2_alloc(MAX_BYTES_PER_SECTOR); - if(!mbr) return -1; + if(mbr == NULL) + return -1; // Read the first sector on the device if(!interface->readSectors(0, 1, mbr)) @@ -249,6 +250,8 @@ int PartitionHandle::FindPartitions() void PartitionHandle::CheckEBR(u8 PartNum, sec_t ebr_lba) { EXTENDED_BOOT_RECORD *ebr = (EXTENDED_BOOT_RECORD *)MEM2_alloc(MAX_BYTES_PER_SECTOR); + if(ebr == NULL) + return; sec_t next_erb_lba = 0; do @@ -293,12 +296,13 @@ void PartitionHandle::CheckEBR(u8 PartNum, sec_t ebr_lba) bool PartitionHandle::CheckGPT(void) { GPT_PARTITION_TABLE *gpt = (GPT_PARTITION_TABLE *)MEM2_alloc(MAX_BYTES_PER_SECTOR); - if(!gpt) return false; + if(gpt == NULL) + return false; bool success = false; // To return false unless at least 1 partition is verified if(!interface->readSectors(1, 33, gpt)) { - free(gpt); + MEM2_free(gpt); return false; // To read all 128 possible partitions } @@ -310,14 +314,19 @@ bool PartitionHandle::CheckGPT(void) || (le64(gpt->First_Usable_LBA) != 34) || (gpt->Reserved != 0)) { - free(gpt); + MEM2_free(gpt); return false; } for(u8 i = 0; i < le32(gpt->Num_Entries) && PartitionList.size() <= 8; i++) { - GUID_PARTITION_ENTRY * entry = (GUID_PARTITION_ENTRY *) &gpt->partitions[i]; + GUID_PARTITION_ENTRY *entry = (GUID_PARTITION_ENTRY *) &gpt->partitions[i]; VOLUME_BOOT_RECORD *vbr = (VOLUME_BOOT_RECORD*)MEM2_alloc(MAX_BYTES_PER_SECTOR); + if(vbr == NULL) + { + MEM2_free(gpt); + return false; + } int Start = le64(entry->First_LBA); int End = le64(entry->Last_LBA); @@ -378,9 +387,9 @@ bool PartitionHandle::CheckGPT(void) success = true; PartitionList.push_back(PartitionEntry); } - free(vbr); + MEM2_free(vbr); } - free(gpt); + MEM2_free(gpt); return success; } diff --git a/source/gc/fileOps.c b/source/gc/fileOps.c index e7474747..759e1b98 100644 --- a/source/gc/fileOps.c +++ b/source/gc/fileOps.c @@ -196,10 +196,12 @@ bool fsop_CopyFile (char *source, char *target, progress_callback_t spinner, voi // Return to beginning.... fseek(fs, 0, SEEK_SET); - u8 * threadStack = NULL; + u8 *threadStack = NULL; lwp_t hthread = LWP_THREAD_NULL; buff = MEM2_alloc(block*2); + if(buff == NULL) + return false; blockIdx = 0; blockReady = 0; @@ -207,6 +209,9 @@ bool fsop_CopyFile (char *source, char *target, progress_callback_t spinner, voi blockInfo[1] = 0; threadStack = MEM2_alloc(STACKSIZE); + if(threadStack == NULL) + return false; + LWP_CreateThread (&hthread, thread_CopyFileReader, NULL, threadStack, STACKSIZE, 30); while (stopThread != 0) diff --git a/source/gc/gc.c b/source/gc/gc.c index a5bd92c4..0a044f3d 100644 --- a/source/gc/gc.c +++ b/source/gc/gc.c @@ -151,6 +151,8 @@ void DML_New_SetOptions(char *GamePath, char *CheatPath, char *NewCheatPath, boo gprintf("Wiiflow DML: Launch game 'sd:/games/%s/game.iso' through memory (new method)\n", GamePath); DMLCfg = (DML_CFG*)MEM2_alloc(sizeof(DML_CFG)); + if(DMLCfg == NULL) + return; memset(DMLCfg, 0, sizeof(DML_CFG)); DMLCfg->Magicbytes = 0xD1050CF6; @@ -222,6 +224,8 @@ void DML_New_SetBootDiscOption() gprintf("Booting GC game\n"); DMLCfg = (DML_CFG*)MEM2_alloc(sizeof(DML_CFG)); + if(DMLCfg == NULL) + return; memset(DMLCfg, 0, sizeof(DML_CFG)); DMLCfg->Magicbytes = 0xD1050CF6; diff --git a/source/gecko/gecko.c b/source/gecko/gecko.c index 9cd0b07a..b8431f23 100644 --- a/source/gecko/gecko.c +++ b/source/gecko/gecko.c @@ -70,6 +70,9 @@ static void USBGeckoOutput() void WriteToFile(char* tmp) { + if(tmpfilebuffer == NULL) + return; + if(bufferMessages) { if((strlen(tmpfilebuffer) + strlen(tmp)) < filebuffer) @@ -77,11 +80,8 @@ void WriteToFile(char* tmp) } else { - if(tmpfilebuffer != NULL) - { - MEM2_free(tmpfilebuffer); - tmpfilebuffer = NULL; - } + MEM2_free(tmpfilebuffer); + tmpfilebuffer = NULL; return; } @@ -100,19 +100,17 @@ void WriteToFile(char* tmp) //using the gprintf from crediar because it is smaller than mine void gprintf( const char *format, ... ) { - char * tmp = NULL; + char *tmp = NULL; va_list va; va_start(va, format); if((vasprintf(&tmp, format, va) >= 0) && tmp) { WriteToFile(tmp); WifiGecko_Send(tmp, strlen(tmp)); - if (geckoinit) - __out_write(NULL, 0, tmp, strlen(tmp)); + __out_write(NULL, 0, tmp, strlen(tmp)); + free(tmp); } va_end(va); - - free(tmp); } char ascii(char s) @@ -157,13 +155,14 @@ void ghexdump(void *d, int len) bool InitGecko() { - if (geckoinit) + if(geckoinit) return geckoinit; USBGeckoOutput(); tmpfilebuffer = (char*)MEM2_alloc(filebuffer + 1 * sizeof(char)); - memset(tmpfilebuffer, 0, sizeof(tmpfilebuffer)); + if(tmpfilebuffer != NULL) + memset(tmpfilebuffer, 0, sizeof(tmpfilebuffer)); #ifdef sd_write_log WriteToSD = true; diff --git a/source/gecko/wifi_gecko.c b/source/gecko/wifi_gecko.c index 5803523e..d30055d6 100644 --- a/source/gecko/wifi_gecko.c +++ b/source/gecko/wifi_gecko.c @@ -131,19 +131,3 @@ int WifiGecko_Send(const char * data, int datasize) return ret; } - -void wifi_printf(const char * format, ...) -{ - if (!init) return; - - char * tmp = NULL; - va_list va; - va_start(va, format); - if((vasprintf(&tmp, format, va) >= 0) && tmp) - { - WifiGecko_Send(tmp, strlen(tmp)); - } - va_end(va); - - free(tmp); -} diff --git a/source/gecko/wifi_gecko.h b/source/gecko/wifi_gecko.h index 264d50d7..130e53c5 100644 --- a/source/gecko/wifi_gecko.h +++ b/source/gecko/wifi_gecko.h @@ -36,7 +36,6 @@ void WifiGecko_Init(const char *ip, u16 port); int WifiGecko_Connect(); void WifiGecko_Close(); int WifiGecko_Send(const char * data, int datasize); -void wifi_printf(const char * format, ...); #ifdef __cplusplus } diff --git a/source/gui/WiiMovie.cpp b/source/gui/WiiMovie.cpp index 3cfcfb6a..d9703e3b 100644 --- a/source/gui/WiiMovie.cpp +++ b/source/gui/WiiMovie.cpp @@ -131,7 +131,8 @@ bool WiiMovie::Play(bool loop) gprintf("Start playing video\n"); PlayThreadStack = (u8 *)MEM2_alloc(32768); - if (PlayThreadStack == NULL) return false; + if (PlayThreadStack == NULL) + return false; Playing = true; PlayTime.reset(); @@ -151,13 +152,13 @@ void WiiMovie::Stop() gprintf("Stopping WiiMovie video\n"); ExitRequested = true; if (PlayThread != LWP_THREAD_NULL) - { LWP_JoinThread(PlayThread, NULL); - } + PlayThread = LWP_THREAD_NULL; gprintf("Playing thread stopped\n"); - MEM2_free(PlayThreadStack); + if(PlayThreadStack != NULL) + MEM2_free(PlayThreadStack); } void WiiMovie::SetVolume(int vol) diff --git a/source/gui/gcvid.cpp b/source/gui/gcvid.cpp index 070ce2a5..2df6696b 100644 --- a/source/gui/gcvid.cpp +++ b/source/gui/gcvid.cpp @@ -300,7 +300,8 @@ const u8* VideoFrame::getData() const void VideoFrame::dealloc() { - MEM2_free(_data); + if(_data != NULL) + MEM2_free(_data); _w = _h = _p = 0; } diff --git a/source/gui/pngu.c b/source/gui/pngu.c index 7043525d..2c2921f4 100644 --- a/source/gui/pngu.c +++ b/source/gui/pngu.c @@ -79,16 +79,18 @@ IMGCTX PNGU_SelectImageFromDevice (const char *filename) return NULL; IMGCTX ctx = MEM2_alloc(sizeof (struct _IMGCTX)); - if (!ctx) return NULL; + if (ctx == NULL) + return NULL; ctx->buffer = NULL; ctx->source = PNGU_SOURCE_DEVICE; ctx->cursor = 0; ctx->filename = MEM2_alloc(strlen (filename) + 1); - if (!ctx->filename) + if (ctx->filename == NULL) { - MEM2_free(ctx); + if(ctx != NULL) + MEM2_free(ctx); return NULL; } strcpy(ctx->filename, filename); diff --git a/source/loader/cios.cpp b/source/loader/cios.cpp index 84204170..0a790d00 100644 --- a/source/loader/cios.cpp +++ b/source/loader/cios.cpp @@ -45,7 +45,7 @@ bool cIOSInfo::D2X(u8 ios, u8 *base) if(!info) return false; *base = (u8)info->baseios; - free(info); + MEM2_free(info); return true; } @@ -59,25 +59,27 @@ iosinfo_t *cIOSInfo::GetInfo(u8 ios) u32 TMD_Length; if (ES_GetStoredTMDSize(TITLE_ID(1, ios), &TMD_Length) < 0) return NULL; - signed_blob *TMD = (signed_blob*) MEM2_alloc(ALIGN32(TMD_Length)); - if (!TMD) return NULL; + signed_blob *TMD = (signed_blob*)MEM2_alloc(ALIGN32(TMD_Length)); + if (TMD == NULL) + return NULL; if (ES_GetStoredTMD(TITLE_ID(1, ios), TMD, TMD_Length) < 0) { - free(TMD); + MEM2_free(TMD); return NULL; } char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); sprintf(filepath, "/title/00000001/%08x/content/%08x.app", ios, *(u8 *)((u32)TMD+0x1E7)); - free(TMD); + MEM2_free(TMD); u32 size = 0; - u8 *buffer = ISFS_GetFile((u8 *) filepath, &size, sizeof(iosinfo_t)); - if(buffer == NULL || size == 0) return NULL; + u8 *buffer = ISFS_GetFile((u8 *)filepath, &size, sizeof(iosinfo_t)); + if(buffer == NULL || size == 0) + return NULL; - iosinfo_t *iosinfo = (iosinfo_t *) buffer; + iosinfo_t *iosinfo = (iosinfo_t *)buffer; bool baseMatch = false; for(u8 i = 0; i < ARRAY_SIZE(allowedBases); i++) @@ -93,10 +95,9 @@ iosinfo_t *cIOSInfo::GetInfo(u8 ios) || !baseMatch /* Base */ || strncasecmp(iosinfo->name, "d2x", 3) != 0) /* Name */ { - free(buffer); + MEM2_free(buffer); return NULL; } - free(buffer); - + return iosinfo; } diff --git a/source/loader/frag.c b/source/loader/frag.c index f56b603f..0e2a6194 100644 --- a/source/loader/frag.c +++ b/source/loader/frag.c @@ -161,15 +161,19 @@ int get_frag_list(u8 *id, char *path, const u32 hdd_sector_size) u32 length = strlen(path); strcpy(fname, path); - if(fname[length-1] > '0' && fname[length-1] < '9') return 0; + int ret, ret_val = -1; + u32 i, j; + + if(fname[length-1] > '0' && fname[length-1] < '9') + return 0; bool isWBFS = wbfs_part_fs != PART_FS_WBFS && strcasestr(strrchr(fname,'.'), ".wbfs") != 0; struct stat st; FragList *fs = MEM2_alloc(sizeof(FragList)); FragList *fa = MEM2_alloc(sizeof(FragList)); FragList *fw = MEM2_alloc(sizeof(FragList)); - int ret, ret_val = -1; - u32 i, j; + if(fs == NULL || fa == NULL || fw == NULL) + goto out; frag_init(fa, MAX_FRAG); @@ -238,6 +242,9 @@ int get_frag_list(u8 *id, char *path, const u32 hdd_sector_size) } frag_list = MEM2_alloc((sizeof(FragList)+31)&(~31)); + if(frag_list == NULL) + goto out; + frag_init(frag_list, MAX_FRAG); if (isWBFS) // If this is a .wbfs file format, remap. { @@ -255,23 +262,26 @@ int get_frag_list(u8 *id, char *path, const u32 hdd_sector_size) goto out; } WBFS_CloseDisc(disc); // Close before jumping on fail. - if (frag_remap(frag_list, fw, fa)) + if(frag_remap(frag_list, fw, fa)) { ret_val = -6; goto out; } } - else memcpy(frag_list, fa, sizeof(FragList)); // .iso files do not need a remap, just copy + else + memcpy(frag_list, fa, sizeof(FragList)); // .iso files do not need a remap, just copy ret_val = 0; out: - if (ret_val) + if (frag_list != NULL) MEM2_free(frag_list); - MEM2_free(fs); - MEM2_free(fa); - MEM2_free(fw); - + if(fs != NULL) + MEM2_free(fs); + if(fa != NULL) + MEM2_free(fa); + if(fw != NULL) + MEM2_free(fw); return ret_val; } diff --git a/source/loader/fs.c b/source/loader/fs.c index fc426353..da6100f3 100644 --- a/source/loader/fs.c +++ b/source/loader/fs.c @@ -20,7 +20,7 @@ u8 *ISFS_GetFile(u8 *path, u32 *size, s32 length) { if (length <= 0) length = stats.file_length; if (length > 0) - buf = (u8 *) MEM2_alloc(ALIGN32(length)); + buf = (u8 *)MEM2_alloc(ALIGN32(length)); if (buf) { @@ -28,7 +28,7 @@ u8 *ISFS_GetFile(u8 *path, u32 *size, s32 length) if (ISFS_Read(fd, (char*)buf, length) != length) { *size = 0; - free(buf); + MEM2_free(buf); } } } @@ -40,6 +40,5 @@ u8 *ISFS_GetFile(u8 *path, u32 *size, s32 length) DCFlushRange(buf, *size); ICInvalidateRange(buf, *size); } - return buf; -} \ No newline at end of file +} diff --git a/source/loader/gc_disc.cpp b/source/loader/gc_disc.cpp index 6ab27a1a..81090147 100644 --- a/source/loader/gc_disc.cpp +++ b/source/loader/gc_disc.cpp @@ -48,6 +48,9 @@ static u8 *FSTable ALIGNED(32); void GCDump::__AnalizeMultiDisc() { u8 *Buffer = (u8 *)MEM2_alloc(0x10); + if(Buffer == NULL) + return; + MultiGameCnt = 0; while(1) { @@ -169,7 +172,9 @@ s32 GCDump::__DiscWriteFile(FILE *f, u64 offset, u32 length, u8 *ReadBuffer) bool GCDump::__WaitForDisc(u8 dsc, u32 msg) { u8 *ReadBuffer = (u8 *)MEM2_alloc(0x440); - + if(ReadBuffer == NULL) + return false; + u32 cover = 0; bool done = false; while(!done) @@ -200,7 +205,7 @@ bool GCDump::__WaitForDisc(u8 dsc, u32 msg) MEM2_free(ReadBuffer); return false; } - + if(Disc_IsGC() == 0) { s32 ret = __DiscReadRaw(ReadBuffer, NextOffset, 0x440); @@ -209,10 +214,10 @@ bool GCDump::__WaitForDisc(u8 dsc, u32 msg) MEM2_free(ReadBuffer); return false; } - + ID2 = *(vu32*)(ReadBuffer); Disc2 = *(vu8*)(ReadBuffer+0x06); - + if(ID == ID2 && Disc2 == dsc) { done = true; @@ -255,6 +260,8 @@ s32 GCDump::DumpGame() static gc_discHdr gcheader ATTRIBUTE_ALIGN(32); u8 *ReadBuffer = (u8 *)MEM2_alloc(gc_readsize); + if(ReadBuffer == NULL) + return 0x31100; gc_done = 0; gamedone = false; @@ -331,6 +338,8 @@ s32 GCDump::DumpGame() DiscSize = DataSize + GamePartOffset; FSTBuffer = (u8 *)MEM2_alloc((FSTSize+31)&(~31)); + if(FSTBuffer == NULL) + return 0x31100; ret = __DiscReadRaw(FSTBuffer, FSTOffset+NextOffset, (FSTSize+31)&(~31)); @@ -470,9 +479,8 @@ s32 GCDump::DumpGame() } gprintf("Done!! Disc size: %d\n", DiscSize); } - MEM2_free(FSTBuffer); - + if(FSTTotal > FSTSize && !multigamedisc) { if(Disc) @@ -512,6 +520,9 @@ s32 GCDump::CheckSpace(u32 *needed, bool comp) static gc_discHdr gcheader ATTRIBUTE_ALIGN(32); u8 *ReadBuffer = (u8 *)MEM2_alloc(0x440); + if(ReadBuffer == NULL) + return 1; + u32 size = 0; bool scnddisc = false; gamedone = false; @@ -573,6 +584,8 @@ s32 GCDump::CheckSpace(u32 *needed, bool comp) else { u8 *FSTBuffer = (u8 *)MEM2_alloc((FSTSize+31)&(~31)); + if(FSTBuffer == NULL) + return 1; ret = __DiscReadRaw(FSTBuffer, FSTOffset+NextOffset, (FSTSize+31)&(~31)); if(ret > 0) diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index bf39c0d3..bca444a4 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -1872,7 +1872,7 @@ bool CMenu::_loadChannelList(void) } else gprintf("Openning %s failed returning %i\n", filepath, file); - free(sysconf); + MEM2_free(sysconf); } sprintf(filepath, "/shared2/menu/FaceLib/RFL_DB.dat"); @@ -1890,7 +1890,7 @@ bool CMenu::_loadChannelList(void) } else gprintf("Openning %s failed returning %i\n", filepath, file); - free(meez); + MEM2_free(meez); } first = false; } @@ -2186,6 +2186,9 @@ void CMenu::_loadDefaultFont(bool korean) // Read content.map from ISFS u8 *content = ISFS_GetFile((u8 *) "/shared1/content.map", &size, 0); + if(content == NULL) + return; + int items = size / sizeof(map_entry_t); //gprintf("Open content.map, size %d, items %d\n", size, items); @@ -2203,7 +2206,6 @@ retry: memcpy(u8_font_filename+9, cm[i].filename, 8); u8 *u8_font_archive = ISFS_GetFile((u8 *) u8_font_filename, &size, 0); - //gprintf("Opened fontfile: %s: %d bytes\n", u8_font_filename, size); if (u8_font_archive != NULL) @@ -2216,8 +2218,8 @@ retry: memcpy(m_base_font.get(), font_file, size); if(!!m_base_font) m_base_font_size = size; + MEM2_free(u8_font_archive); } - free(u8_font_archive); break; } } @@ -2228,7 +2230,7 @@ retry: goto retry; } - free(content); + MEM2_free(content); } void CMenu::_cleanupDefaultFont() @@ -2301,13 +2303,12 @@ bool CMenu::MIOSisDML() if(*(u32*)(appfile+i) == 0x44494F53) { gprintf("DML is installed as MIOS\n"); - free(appfile); + MEM2_free(appfile); return true; } } + MEM2_free(appfile); } - - free(appfile); gprintf("DML is not installed as MIOS\n"); return false; } diff --git a/source/menu/menu_about.cpp b/source/menu/menu_about.cpp index e19c6653..7bc43922 100644 --- a/source/menu/menu_about.cpp +++ b/source/menu/menu_about.cpp @@ -180,7 +180,7 @@ void CMenu::_textAbout(void) iosinfo_t * iosInfo = cIOSInfo::GetInfo(mainIOS); if(iosInfo != NULL) m_btnMgr.setText(m_aboutLblIOS, wfmt(_fmt("ios", L"IOS%i base %i v%i"), mainIOS, iosInfo->baseios, iosInfo->version), true); - free(iosInfo); + MEM2_free(iosInfo); if(m_current_view == COVERFLOW_CHANNEL && m_cfg.getInt("NAND", "emulation", 0) > 0) Nand::Instance()->Enable_Emu(); diff --git a/source/menu/menu_download.cpp b/source/menu/menu_download.cpp index d42de396..68b7a03e 100644 --- a/source/menu/menu_download.cpp +++ b/source/menu/menu_download.cpp @@ -398,7 +398,7 @@ bool CMenu::_isNetworkAvailable() if (buf && size > 4) { retval = buf[4] > 0; // There is a valid connection defined. - free(buf); + MEM2_free(buf); } return retval; }