There's a win32 api function called CreateRemoteThread(). I was wondering if the thread exits cleanly if you use it. I heard it is quite untidy (the return handle). When used with VirtualAllocEx, it never gets deallocated. Just wondering if anyone can elaborate on that or even show some examples how to use it properly and what isn't the proper way to use it. Thanks
Posted on 2004-12-23 16:56:27 by Randomizer
When a thread exits with a normal ret, windows takes care of cleaning up (you must, of course, close the handle returned by Create*Thread yourself to avoid kernel-mode object leaks - not that using CloseHandle on the thread handle does *not* terminate the thread). You get leaks if you use TerminateThread.

As for the memory allocated with VirtualAllocEx, just free it once the thread has terminated: you could WaitForSingleObject on the thread handle, then CloseHandle, then VirtualFreeEx.
Posted on 2004-12-24 06:56:37 by f0dder