Fixed memory leaks

Close #4945
This commit is contained in:
Rajendra Singh 2018-10-21 12:56:48 +05:30 committed by Don HO
parent 17ac06f83a
commit fd52450d16
4 changed files with 20 additions and 6 deletions

View File

@ -952,7 +952,6 @@ bool str2Clipboard(const generic_string &str2cpy, HWND hwnd)
unsigned int clipBoardFormat = CF_UNICODETEXT;
if (::SetClipboardData(clipBoardFormat, hglbCopy) == NULL)
{
::GlobalUnlock(hglbCopy);
::GlobalFree(hglbCopy);
::CloseClipboard();
return false;

View File

@ -98,6 +98,7 @@ bool MiniDumper::writeDump(EXCEPTION_POINTERS * pExceptionInfo)
{
szResult = TEXT("The debugging DLL is outdated,\r\nfind a recent copy of dbghelp.dll and install it.");
}
::FreeLibrary(hDll);
}
else
{

View File

@ -345,7 +345,13 @@ bool PluginsManager::loadPluginsV2(const TCHAR* dir)
generic_string dllName2 = foundData.cFileName;
dllName2 += TEXT(".dll");
PathAppend(pluginsFullPathFilter2, dllName2);
// get plugin
if (hFindDll)
{
::FindClose(hFindDll);
hFindDll = INVALID_HANDLE_VALUE;
}
hFindDll = ::FindFirstFile(pluginsFullPathFilter2.c_str(), &foundData);
if (hFindDll != INVALID_HANDLE_VALUE && !(foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{

View File

@ -79,7 +79,7 @@ void Version::setVersionFrom(generic_string filePath)
{
if (not filePath.empty() && ::PathFileExists(filePath.c_str()))
{
DWORD handle;
DWORD handle = 0;
DWORD bufferSize = ::GetFileVersionInfoSize(filePath.c_str(), &handle);
if (bufferSize <= 0)
@ -88,9 +88,9 @@ void Version::setVersionFrom(generic_string filePath)
unsigned char* buffer = new unsigned char[bufferSize];
::GetFileVersionInfo(filePath.c_str(), handle, bufferSize, buffer);
VS_FIXEDFILEINFO* lpFileInfo;
VS_FIXEDFILEINFO* lpFileInfo = nullptr;
UINT cbFileInfo = 0;
VerQueryValue(buffer, TEXT("\\"), (LPVOID*)&lpFileInfo, &cbFileInfo);
VerQueryValue(buffer, TEXT("\\"), reinterpret_cast<LPVOID*>(&lpFileInfo), &cbFileInfo);
if (cbFileInfo)
{
_major = (lpFileInfo->dwFileVersionMS & 0xFFFF0000) >> 16;
@ -98,6 +98,7 @@ void Version::setVersionFrom(generic_string filePath)
_patch = (lpFileInfo->dwFileVersionLS & 0xFFFF0000) >> 16;
_build = lpFileInfo->dwFileVersionLS & 0x0000FFFF;
}
delete[] buffer;
}
}
@ -714,7 +715,10 @@ bool PluginsAdminDlg::isValide()
bool PluginsAdminDlg::updateListAndLoadFromJson()
{
try {
HMODULE hLib = NULL;
try
{
if (!isValide())
return false;
@ -728,7 +732,7 @@ bool PluginsAdminDlg::updateListAndLoadFromJson()
#else //RELEASE
HINSTANCE hLib = ::LoadLibrary(_pluginListFullPath.c_str());
hLib = ::LoadLibrary(_pluginListFullPath.c_str());
if (!hLib)
{
// Error treatment
@ -741,6 +745,7 @@ bool PluginsAdminDlg::updateListAndLoadFromJson()
{
// Error treatment
//printStr(TEXT("getList PB!!!"));
::FreeLibrary(hLib);
return false;
}
@ -770,11 +775,14 @@ bool PluginsAdminDlg::updateListAndLoadFromJson()
// initialize installed list view
loadFromPluginInfos();
::FreeLibrary(hLib);
return true;
}
catch (...)
{
// whichever exception
if (hLib)
::FreeLibrary(hLib);
return false;
}
}