Fixed a few memory leaks found by VLD.

This commit is contained in:
LoRd_MuldeR 2012-04-06 23:15:58 +02:00
parent 7016383fbb
commit f05365e383
7 changed files with 496 additions and 477 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -29,8 +29,8 @@
#define VER_LAMEXP_MINOR_HI 0
#define VER_LAMEXP_MINOR_LO 4
#define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 13
#define VER_LAMEXP_BUILD 957
#define VER_LAMEXP_PATCH 14
#define VER_LAMEXP_BUILD 958
///////////////////////////////////////////////////////////////////////////////
// Tool versions (minimum expected versions!)

View File

@ -494,6 +494,7 @@ MainWindow::~MainWindow(void)
LAMEXP_DELETE(m_encoderButtonGroup);
LAMEXP_DELETE(m_sourceFilesContextMenu);
LAMEXP_DELETE(m_outputFolderFavoritesMenu);
LAMEXP_DELETE(m_outputFolderContextMenu);
LAMEXP_DELETE(m_dropBox);
}
@ -1563,7 +1564,11 @@ void MainWindow::styleActionActivated(QAction *action)
}
//Force re-translate after style change
changeEvent(new QEvent(QEvent::LanguageChange));
if(QEvent *e = new QEvent(QEvent::LanguageChange))
{
changeEvent(e);
LAMEXP_DELETE(e);
}
}
/*

View File

@ -1658,15 +1658,17 @@ QString lamexp_known_folder(lamexp_known_folder_t folder_id)
static const GUID GUID_PROGRAM_FILES = {0x905e63b6,0xc1bf,0x494e,{0xb2,0x9c,0x65,0xb7,0x32,0xd3,0xd2,0x1a}};
static const GUID GUID_SYSTEM_FOLDER = {0x1AC14E77,0x02E7,0x4E5D,{0xB7,0x44,0x2E,0xB1,0xAE,0x51,0x98,0xB7}};
static QLibrary *Kernel32Lib = NULL;
static SHGetKnownFolderPathFun SHGetKnownFolderPathPtr = NULL;
static SHGetFolderPathFun SHGetFolderPathPtr = NULL;
if((!SHGetKnownFolderPathPtr) && (!SHGetFolderPathPtr))
{
if(!Kernel32Lib) Kernel32Lib = new QLibrary("shell32.dll");
SHGetKnownFolderPathPtr = (SHGetKnownFolderPathFun) Kernel32Lib->resolve("SHGetKnownFolderPath");
SHGetFolderPathPtr = (SHGetFolderPathFun) Kernel32Lib->resolve("SHGetFolderPathW");
QLibrary kernel32Lib("shell32.dll");
if(kernel32Lib.load())
{
SHGetKnownFolderPathPtr = (SHGetKnownFolderPathFun) kernel32Lib.resolve("SHGetKnownFolderPath");
SHGetFolderPathPtr = (SHGetFolderPathFun) kernel32Lib.resolve("SHGetFolderPathW");
}
}
int folderCSIDL = -1;
@ -2024,6 +2026,23 @@ void lamexp_finalization(void)
LAMEXP_DELETE(g_lamexp_ipc_ptr.sharedmem);
LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read);
LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write);
LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read_mutex);
LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write_mutex);
//Free STDOUT and STDERR buffers
if(g_lamexp_console_attached)
{
if(std::filebuf *tmp = dynamic_cast<std::filebuf*>(std::cout.rdbuf()))
{
std::cout.rdbuf(NULL);
LAMEXP_DELETE(tmp);
}
if(std::filebuf *tmp = dynamic_cast<std::filebuf*>(std::cerr.rdbuf()))
{
std::cerr.rdbuf(NULL);
LAMEXP_DELETE(tmp);
}
}
//Close log file
if(g_lamexp_log_file)

View File

@ -40,10 +40,10 @@ typedef BOOL (WINAPI *AssignProcessToJobObjectFun)(__in HANDLE hJob, __in HANDLE
/*
* Static vars
*/
quint64 AbstractTool::m_lastLaunchTime = 0ui64;
QMutex *AbstractTool::m_mutex_startProcess = NULL;
HANDLE AbstractTool::m_handle_jobObject = NULL;
unsigned int AbstractTool::m_jobObjRefCount = 0U;
quint64 AbstractTool::s_lastLaunchTime = 0ui64;
QMutex AbstractTool::s_mutex_startProcess;
HANDLE AbstractTool::s_handle_jobObject = NULL;
unsigned int AbstractTool::s_jobObjRefCount = 0U;
/*
* Const
@ -59,14 +59,9 @@ AbstractTool::AbstractTool(void)
static CreateJobObjectFun CreateJobObjectPtr = NULL;
static SetInformationJobObjectFun SetInformationJobObjectPtr = NULL;
if(!m_mutex_startProcess)
{
m_mutex_startProcess = new QMutex();
}
QMutexLocker lock(&s_mutex_startProcess);
QMutexLocker lock(m_mutex_startProcess);
if(m_jobObjRefCount < 1U)
if(s_jobObjRefCount < 1U)
{
DWORD osVersionNo = lamexp_get_os_version();
if(LAMEXP_MIN_OS_VER(osVersionNo, 5, 1))
@ -89,8 +84,8 @@ AbstractTool::AbstractTool(void)
jobExtendedLimitInfo.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE | JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION;
if(SetInformationJobObjectPtr(jobObject, JobObjectExtendedLimitInformation, &jobExtendedLimitInfo, sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION)))
{
m_handle_jobObject = jobObject;
m_jobObjRefCount = 1U;
s_handle_jobObject = jobObject;
s_jobObjRefCount = 1U;
}
else
{
@ -106,7 +101,7 @@ AbstractTool::AbstractTool(void)
}
else
{
m_jobObjRefCount++;
s_jobObjRefCount++;
}
m_firstLaunch = true;
@ -117,15 +112,15 @@ AbstractTool::AbstractTool(void)
*/
AbstractTool::~AbstractTool(void)
{
QMutexLocker lock(m_mutex_startProcess);
QMutexLocker lock(&s_mutex_startProcess);
if(m_jobObjRefCount >= 1U)
if(s_jobObjRefCount >= 1U)
{
m_jobObjRefCount--;
if((m_jobObjRefCount < 1U) && m_handle_jobObject)
s_jobObjRefCount--;
if((s_jobObjRefCount < 1U) && s_handle_jobObject)
{
CloseHandle(m_handle_jobObject);
m_handle_jobObject = NULL;
CloseHandle(s_handle_jobObject);
s_handle_jobObject = NULL;
}
}
}
@ -137,9 +132,9 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
{
static AssignProcessToJobObjectFun AssignProcessToJobObjectPtr = NULL;
QMutexLocker lock(m_mutex_startProcess);
QMutexLocker lock(&s_mutex_startProcess);
if(currentTime() <= m_lastLaunchTime)
if(currentTime() <= s_lastLaunchTime)
{
Sleep(START_DELAY);
}
@ -164,9 +159,9 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
if(process.waitForStarted())
{
if(AssignProcessToJobObjectPtr && m_handle_jobObject)
if(AssignProcessToJobObjectPtr && s_handle_jobObject)
{
if(!AssignProcessToJobObjectPtr(m_handle_jobObject, process.pid()->hProcess))
if(!AssignProcessToJobObjectPtr(s_handle_jobObject, process.pid()->hProcess))
{
qWarning("Failed to assign process to job object!");
}
@ -184,7 +179,7 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
m_firstLaunch = false;
}
m_lastLaunchTime = currentTime() + START_DELAY_NANO;
s_lastLaunchTime = currentTime() + START_DELAY_NANO;
return true;
}
@ -195,7 +190,7 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
process.kill();
process.waitForFinished(-1);
m_lastLaunchTime = currentTime() + START_DELAY_NANO;
s_lastLaunchTime = currentTime() + START_DELAY_NANO;
return false;
}

View File

@ -47,10 +47,10 @@ protected:
static const int m_processTimeoutInterval = 600000;
private:
static quint64 m_lastLaunchTime;
static QMutex *m_mutex_startProcess;
static unsigned int m_jobObjRefCount;
static void *m_handle_jobObject;
static quint64 s_lastLaunchTime;
static QMutex s_mutex_startProcess;
static unsigned int s_jobObjRefCount;
static void *s_handle_jobObject;
bool m_firstLaunch;
};