From 0cb7934d939f9a02d4784906f8d3a011e524fa30 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Mon, 3 Aug 2009 22:51:13 +0000 Subject: [PATCH] fix some memleaks in DiscIO. Fix for issue 1238. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3936 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/DiscIO/Src/BannerLoader.cpp | 4 +- Source/Core/DiscIO/Src/BannerLoaderWii.cpp | 6 +- Source/Core/DiscIO/Src/CompressedBlob.cpp | 2 +- Source/Core/DiscIO/Src/DiscScrubber.cpp | 13 +- Source/Core/DiscIO/Src/DriveBlob.cpp | 2 +- Source/Core/DiscIO/Src/Filesystem.h | 2 +- Source/Core/DiscIO/Src/NANDContentLoader.cpp | 8 +- Source/Core/DolphinWX/Src/ISOProperties.cpp | 6 +- Source/UnitTests/UnitTests.cpp | 1 + Source/UnitTests/UnitTests.vcproj | 155 ------------------- 10 files changed, 22 insertions(+), 177 deletions(-) diff --git a/Source/Core/DiscIO/Src/BannerLoader.cpp b/Source/Core/DiscIO/Src/BannerLoader.cpp index b18fc61dc8..465e8df3ad 100644 --- a/Source/Core/DiscIO/Src/BannerLoader.cpp +++ b/Source/Core/DiscIO/Src/BannerLoader.cpp @@ -114,10 +114,10 @@ bool IBannerLoader::CopyBeUnicodeToString( std::string& _rDestination, const u16 _rDestination = pAnsiStrBuffer; returnCode = true; } - delete pAnsiStrBuffer; + delete[] pAnsiStrBuffer; } } - delete buffer; + delete[] buffer; } } #else diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp index 47bac0fec4..4b71155ba8 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp @@ -122,7 +122,7 @@ bool CBannerLoaderWii::GetBanner(u32* _pBannerImage) { SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; - u32 Buffer[192 * 64]; + u32* Buffer = new u32[192 * 64]; decode5A3image(Buffer, (u16*)pBanner->m_BannerTexture, 192, 64); // ugly scaling :) TODO: at least a 2x2 box filter, preferably a 3x3 gaussian :) @@ -132,7 +132,9 @@ bool CBannerLoaderWii::GetBanner(u32* _pBannerImage) { _pBannerImage[y*96+x] = Buffer[(y*192*2) + (x*2)]; } - } + } + delete pBanner; + delete[] Buffer; } return true; } diff --git a/Source/Core/DiscIO/Src/CompressedBlob.cpp b/Source/Core/DiscIO/Src/CompressedBlob.cpp index 14b686fd46..1866f7a789 100644 --- a/Source/Core/DiscIO/Src/CompressedBlob.cpp +++ b/Source/Core/DiscIO/Src/CompressedBlob.cpp @@ -227,7 +227,7 @@ bool CompressFileToBlob(const char* infile, const char* outfile, u32 sub_type, offsets[i] = position; // u64 start = i * header.block_size; // u64 size = header.block_size; - memset(in_buf, 0, header.block_size); + std::fill(in_buf, in_buf + header.block_size, 0); fread(in_buf, header.block_size, 1, inf); z_stream z; memset(&z, 0, sizeof(z)); diff --git a/Source/Core/DiscIO/Src/DiscScrubber.cpp b/Source/Core/DiscIO/Src/DiscScrubber.cpp index f76f8a10ea..e04e997d17 100644 --- a/Source/Core/DiscIO/Src/DiscScrubber.cpp +++ b/Source/Core/DiscIO/Src/DiscScrubber.cpp @@ -123,7 +123,7 @@ bool Scrub(const char* filename, CompressCB callback, void* arg) m_Disc = CreateVolumeFromFilename(filename); m_FileSize = m_Disc->GetSize(); - u64 numClusters = m_FileSize / CLUSTER_SIZE; + u32 numClusters = (u32)(m_FileSize / CLUSTER_SIZE); // Warn if not DVD5 or DVD9 size if (numClusters != 0x23048 && numClusters != 0x46090) @@ -158,7 +158,7 @@ bool Scrub(const char* filename, CompressCB callback, void* arg) // Modify file, obeying the table of free blocks NOTICE_LOG(DISCIO, "Removing garbage data...go get some coffee :)"); - for (u64 i = 0; i < numClusters; i++) + for (u32 i = 0; i < numClusters; i++) { u64 CurrentOffset = i * CLUSTER_SIZE; @@ -184,7 +184,7 @@ bool Scrub(const char* filename, CompressCB callback, void* arg) if (i % (numClusters / 1000) == 0) { char temp[512]; - sprintf(temp, "DiscScrubber: %llu/%llu (%s)", i, numClusters, m_FreeTable[i] ? "Free" : "Used"); + sprintf(temp, "DiscScrubber: %lu/%lu (%s)", i, numClusters, m_FreeTable[i] ? "Free" : "Used"); callback(temp, (float)i / (float)numClusters, arg); } } @@ -196,8 +196,8 @@ bool Scrub(const char* filename, CompressCB callback, void* arg) cleanup: if (pFile) fclose(pFile); - delete m_Sector1; - delete m_FreeTable; + delete[] m_Sector1; + delete[] m_FreeTable; return success; } @@ -241,10 +241,9 @@ bool MarkAsScrubbed(const char* filename) if (!f) return false; - bool success; u8 ScrubbedFlag[1] = {SCRUBBER_VERSION}; fseek(f, 0x80, SEEK_SET); - success |= fwrite(ScrubbedFlag, 1, 1, f) == 1; + bool success = fwrite(ScrubbedFlag, 1, 1, f) == 1; fclose(f); return success; } diff --git a/Source/Core/DiscIO/Src/DriveBlob.cpp b/Source/Core/DiscIO/Src/DriveBlob.cpp index 94b6a4e627..58a2d84be7 100644 --- a/Source/Core/DiscIO/Src/DriveBlob.cpp +++ b/Source/Core/DiscIO/Src/DriveBlob.cpp @@ -114,7 +114,7 @@ namespace DiscIO fread(lpSector, 1, m_blocksize, file_); #endif memcpy(out_ptr, lpSector, m_blocksize); - delete lpSector; + delete[] lpSector; } bool DriveReader::ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8 *out_ptr) diff --git a/Source/Core/DiscIO/Src/Filesystem.h b/Source/Core/DiscIO/Src/Filesystem.h index b13037422f..86e2fb0f3d 100644 --- a/Source/Core/DiscIO/Src/Filesystem.h +++ b/Source/Core/DiscIO/Src/Filesystem.h @@ -39,7 +39,7 @@ struct SFileInfo SFileInfo(const SFileInfo &rhs) : m_NameOffset(rhs.m_NameOffset), m_Offset(rhs.m_Offset), m_FileSize(rhs.m_FileSize) { - strcpy(m_FullPath, rhs.m_FullPath); + memcpy(m_FullPath, rhs.m_FullPath, strlen(rhs.m_FullPath)); } }; diff --git a/Source/Core/DiscIO/Src/NANDContentLoader.cpp b/Source/Core/DiscIO/Src/NANDContentLoader.cpp index eeda917b31..017c664f1a 100644 --- a/Source/Core/DiscIO/Src/NANDContentLoader.cpp +++ b/Source/Core/DiscIO/Src/NANDContentLoader.cpp @@ -253,12 +253,12 @@ bool CNANDContentLoader::CreateFromDirectory(const std::string& _rPath) FILE* pFile = fopen(szFilename, "rb"); if (pFile != NULL) { - u64 Size = File::GetSize(szFilename); - rContent.m_pData = new u8[(u32)Size]; + u64 ContentSize = File::GetSize(szFilename); + rContent.m_pData = new u8[(u32)ContentSize]; - _dbg_assert_msg_(BOOT, rContent.m_Size==Size, "TMDLoader: Filesize doesnt fit (%s %i)... prolly you have a bad dump", szFilename, i); + _dbg_assert_msg_(BOOT, rContent.m_Size==ContentSize, "TMDLoader: Filesize doesnt fit (%s %i)... prolly you have a bad dump", szFilename, i); - fread(rContent.m_pData, (size_t)Size, 1, pFile); + fread(rContent.m_pData, (size_t)ContentSize, 1, pFile); fclose(pFile); } else diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index 5d2bb17906..375e806b44 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -202,10 +202,8 @@ CISOProperties::~CISOProperties() { for (std::vector::const_iterator PartIter = WiiDisc.begin(); PartIter != WiiDisc.end(); ++PartIter) { - delete PartIter->FileSystem; + delete PartIter->FileSystem; // Also deletes the corresponding PartIter->Files delete PartIter->Partition; - for (std::vector::const_iterator FileIter = PartIter->Files.begin(); FileIter != PartIter->Files.end(); ++FileIter) - delete *FileIter; } } else @@ -1068,7 +1066,7 @@ bool CISOProperties::CopySJISToString( wxString& _rDestination, const char* _src } #endif } - delete pUnicodeStrBuffer; + delete[] pUnicodeStrBuffer; } } #else diff --git a/Source/UnitTests/UnitTests.cpp b/Source/UnitTests/UnitTests.cpp index fe0836c0a8..e7de4a1545 100644 --- a/Source/UnitTests/UnitTests.cpp +++ b/Source/UnitTests/UnitTests.cpp @@ -119,6 +119,7 @@ void Host_UpdateDisasmDialog(){} void Host_UpdateLogDisplay(){} void Host_UpdateMemoryView(){} void Host_NotifyMapLoaded(){} +void Host_ShowJitResults(unsigned int address){} void Host_UpdateBreakPointView(){} void Host_SetDebugMode(bool enable){} diff --git a/Source/UnitTests/UnitTests.vcproj b/Source/UnitTests/UnitTests.vcproj index 0567258611..86a71847e8 100644 --- a/Source/UnitTests/UnitTests.vcproj +++ b/Source/UnitTests/UnitTests.vcproj @@ -323,161 +323,6 @@ ExcludedFromBuild="true" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -