1
0
Fork 0

DBG: new memory allocation/deallocation functions + fixed a handle leak

GUI: fixed a handle leak
This commit is contained in:
Mr. eXoDia 2014-06-24 17:03:32 +02:00
parent df0819b122
commit 5176dd1cd1
5 changed files with 28 additions and 23 deletions

View File

@ -137,8 +137,7 @@ BRIDGE_IMPEXP const char* BridgeStart()
BRIDGE_IMPEXP void* BridgeAlloc(size_t size)
{
//unsigned char* a=(unsigned char*)VirtualAlloc(0, size, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
unsigned char* a=new (std::nothrow)unsigned char[size];
unsigned char* a=(unsigned char*)GlobalAlloc(GMEM_FIXED, size);
if(!a)
{
MessageBoxA(0, "Could not allocate memory", "Error", MB_ICONERROR);
@ -150,8 +149,7 @@ BRIDGE_IMPEXP void* BridgeAlloc(size_t size)
BRIDGE_IMPEXP void BridgeFree(void* ptr)
{
//VirtualFree(ptr, 0, MEM_RELEASE);
delete[] (unsigned char*)ptr;
GlobalFree(ptr);
}
BRIDGE_IMPEXP bool BridgeSettingGet(const char* section, const char* key, char* value)

View File

@ -21,7 +21,7 @@ static char alloctrace[MAX_PATH]="";
void* emalloc(size_t size, const char* reason)
{
unsigned char* a=new (std::nothrow)unsigned char[size];
unsigned char* a=(unsigned char*)GlobalAlloc(GMEM_FIXED, size);
if(!a)
{
MessageBoxA(0, "Could not allocate memory", "Error", MB_ICONERROR);
@ -45,7 +45,7 @@ void efree(void* ptr, const char* reason)
fprintf(file, "DBG%.5d:efree:"fhex":%s\n", emalloc_count, ptr, reason);
fclose(file);
*/
delete[] (unsigned char*)ptr;
GlobalFree(ptr);
}
int memleaks()

View File

@ -269,6 +269,7 @@ extern "C" DLL_EXPORT void _dbg_dbgexitsignal()
wait(WAITID_STOP); //after this, debugging stopped
pluginunload();
TerminateThread(hCommandLoopThread, 0);
CloseHandle(hCommandLoopThread);
cmdfree(command_list);
varfree();
msgfreestack(gMsgStack);

View File

@ -10,7 +10,12 @@ static Bridge* mBridge;
************************************************************************************/
Bridge::Bridge(QObject *parent) : QObject(parent)
{
mBridgeMutex = new QMutex();
}
Bridge::~Bridge()
{
delete mBridgeMutex;
}
void Bridge::CopyToClipboard(const char* text)
@ -90,12 +95,12 @@ void Bridge::emitDumpAt(int_t va)
void Bridge::emitScriptAdd(int count, const char** lines)
{
mBridgeMutex.lock();
mBridgeMutex->lock();
hasBridgeResult=false;
emit scriptAdd(count, lines);
while(!hasBridgeResult) //wait for thread completion
Sleep(100);
mBridgeMutex.unlock();
mBridgeMutex->unlock();
}
void Bridge::emitScriptClear()
@ -130,12 +135,12 @@ void Bridge::emitScriptMessage(QString message)
int Bridge::emitScriptQuestion(QString message)
{
mBridgeMutex.lock();
mBridgeMutex->lock();
hasBridgeResult=false;
emit scriptQuestion(message);
while(!hasBridgeResult) //wait for thread completion
Sleep(100);
mBridgeMutex.unlock();
mBridgeMutex->unlock();
return bridgeResult;
}
@ -231,23 +236,23 @@ void Bridge::emitSetLastException(unsigned int exceptionCode)
int Bridge::emitMenuAddMenu(int hMenu, QString title)
{
mBridgeMutex.lock();
mBridgeMutex->lock();
hasBridgeResult=false;
emit menuAddMenu(hMenu, title);
while(!hasBridgeResult) //wait for thread completion
Sleep(100);
mBridgeMutex.unlock();
mBridgeMutex->unlock();
return bridgeResult;
}
int Bridge::emitMenuAddMenuEntry(int hMenu, QString title)
{
mBridgeMutex.lock();
mBridgeMutex->lock();
hasBridgeResult=false;
emit menuAddMenuEntry(hMenu, title);
while(!hasBridgeResult) //wait for thread completion
Sleep(100);
mBridgeMutex.unlock();
mBridgeMutex->unlock();
return bridgeResult;
}
@ -270,7 +275,7 @@ bool Bridge::emitSelectionGet(int hWindow, SELECTIONDATA* selection)
{
if(!DbgIsDebugging())
return false;
mBridgeMutex.lock();
mBridgeMutex->lock();
hasBridgeResult=false;
switch(hWindow)
{
@ -284,12 +289,12 @@ bool Bridge::emitSelectionGet(int hWindow, SELECTIONDATA* selection)
emit selectionStackGet(selection);
break;
default:
mBridgeMutex.unlock();
mBridgeMutex->unlock();
return false;
}
while(!hasBridgeResult) //wait for thread completion
Sleep(100);
mBridgeMutex.unlock();
mBridgeMutex->unlock();
if(selection->start > selection->end) //swap start and end
{
int_t temp=selection->end;
@ -303,7 +308,7 @@ bool Bridge::emitSelectionSet(int hWindow, const SELECTIONDATA* selection)
{
if(!DbgIsDebugging())
return false;
mBridgeMutex.lock();
mBridgeMutex->lock();
hasBridgeResult=false;
switch(hWindow)
{
@ -317,23 +322,23 @@ bool Bridge::emitSelectionSet(int hWindow, const SELECTIONDATA* selection)
emit selectionStackSet(selection);
break;
default:
mBridgeMutex.unlock();
mBridgeMutex->unlock();
return false;
}
while(!hasBridgeResult) //wait for thread completion
Sleep(100);
mBridgeMutex.unlock();
mBridgeMutex->unlock();
return bridgeResult;
}
bool Bridge::emitGetStrWindow(const QString title, QString* text)
{
mBridgeMutex.lock();
mBridgeMutex->lock();
hasBridgeResult=false;
emit getStrWindow(title, text);
while(!hasBridgeResult) //wait for thread completion
Sleep(100);
mBridgeMutex.unlock();
mBridgeMutex->unlock();
return bridgeResult;
}

View File

@ -19,6 +19,7 @@ class Bridge : public QObject
Q_OBJECT
public:
explicit Bridge(QObject *parent = 0);
~Bridge();
static Bridge* getBridge();
static void initBridge();
@ -137,7 +138,7 @@ signals:
void updateSideBar();
private:
QMutex mBridgeMutex;
QMutex* mBridgeMutex;
int_t bridgeResult;
bool hasBridgeResult;