Fix for Windows XP compatibility
I neglected FreeLibrary and have multiple calls to LoadLibrary without freeing. This is fixed by moving it to the class member level and allocating and deallocating through the class constructor/destructor.
This commit is contained in:
parent
a972773b6a
commit
84c164ff66
|
@ -49,6 +49,12 @@ CScriptInstance::CScriptInstance(CDebuggerUI* debugger)
|
|||
m_hIOCompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);
|
||||
InitializeCriticalSection(&m_CriticalSection);
|
||||
CacheInstance(this);
|
||||
m_hKernel = LoadLibrary("Kernel32.dll");
|
||||
m_CancelIoEx = NULL;
|
||||
if (m_hKernel != NULL)
|
||||
{
|
||||
m_CancelIoEx = (Dynamic_CancelIoEx)GetProcAddress(m_hKernel, "CancelIoEx");
|
||||
}
|
||||
}
|
||||
|
||||
CScriptInstance::~CScriptInstance()
|
||||
|
@ -59,6 +65,11 @@ CScriptInstance::~CScriptInstance()
|
|||
|
||||
TerminateThread(m_hThread, 0);
|
||||
CloseHandle(m_hThread);
|
||||
m_CancelIoEx = NULL;
|
||||
if (m_hKernel != NULL)
|
||||
{
|
||||
FreeLibrary(m_hKernel);
|
||||
}
|
||||
}
|
||||
|
||||
void CScriptInstance::Start(char* path)
|
||||
|
@ -346,8 +357,6 @@ CScriptInstance::AddListener(HANDLE fd, IOEVENTTYPE evt, void* callback, void* d
|
|||
|
||||
void CScriptInstance::RemoveListenerByIndex(UINT index)
|
||||
{
|
||||
typedef BOOL (__stdcall *Dynamic_CancelIoEx)(HANDLE, LPOVERLAPPED);
|
||||
Dynamic_CancelIoEx _CancelIoEx;
|
||||
IOLISTENER* lpListener = m_Listeners[index];
|
||||
|
||||
if (lpListener->data != NULL)
|
||||
|
@ -355,16 +364,18 @@ void CScriptInstance::RemoveListenerByIndex(UINT index)
|
|||
free(lpListener->data);
|
||||
}
|
||||
|
||||
HMODULE hKernel = LoadLibrary("Kernel32.dll");
|
||||
_CancelIoEx = (Dynamic_CancelIoEx)GetProcAddress(hKernel, "CancelIoEx");
|
||||
|
||||
// Original call to CancelIoEx:
|
||||
//CancelIoEx(lpListener->fd, (LPOVERLAPPED)lpListener);
|
||||
if (_CancelIoEx != NULL)
|
||||
_CancelIoEx(lpListener->fd, (LPOVERLAPPED)lpListener);
|
||||
if (m_CancelIoEx != NULL)
|
||||
{
|
||||
m_CancelIoEx(lpListener->fd, (LPOVERLAPPED)lpListener);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This isn't a good replacement and the script aspects of the debugger shouldn't
|
||||
// be used in WindowsXP
|
||||
CancelIo(lpListener->fd);
|
||||
}
|
||||
|
||||
free(lpListener);
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ class CScriptInstance
|
|||
int fd;
|
||||
} FILE_FD;
|
||||
|
||||
typedef BOOL(__stdcall *Dynamic_CancelIoEx)(HANDLE, LPOVERLAPPED);
|
||||
public:
|
||||
|
||||
CScriptInstance(CDebuggerUI* debugger);
|
||||
|
@ -129,6 +130,10 @@ private:
|
|||
|
||||
const char* EvalFile(const char* jsPath);
|
||||
|
||||
// Handle to to dynamically load CancelIoEx for Windows XP compatibility
|
||||
HMODULE m_hKernel;
|
||||
Dynamic_CancelIoEx m_CancelIoEx;
|
||||
|
||||
// Lookup list of CScriptInstance instances for static js_* functions
|
||||
static vector<CScriptInstance*> Cache;
|
||||
static void CacheInstance(CScriptInstance* _this);
|
||||
|
|
Loading…
Reference in New Issue