I am writing a replacement GINA for windows XP. My logon dialog box starts a thread (using CreateThread()) when it loads. The thread is passed the handle to the dialog box and then monitors the the registry for specific changes in order to adjust my dialog box's controls accordingly. Whenever the dialog is refreshed or closed I send a TerminateThread() command to end the thread so that when the logon dialog box reloads itself I dont't get multiple threads running. However this method seems to be causing some memory issues. According to MSDN, TerminateThread() is a risky call for this reason.
I am new to C and know almost nothing about memory allocation. All I am doing in the thread is getting some handles to some graphic controls and using those handles to manipulate the graphics on the dialog box. I have noticed that everytime i refresh the dialog, windows alocates more memory. This can continue until the machine has no available memory left. It seems to me that the above quote would explain this memory leak."If the target thread is allocating memory from the heap, the heap lock will not be released."
Is there a command I can call everytime I terminate the thread that will also look for unused memory and de-allocate it? Thanks for your help.