I need one clarification related to the Windows Threads (WEC7). Consider the following sample code. I would like to know whether any memory leak in the code.
In the code snippet MyThread1 creates memory in the heap and passed to MyThread2 and the allocated memory is cleared there.
DWORD WINAPI MyThread2(LPVOID lpVoid)
{
int* b = (int*)lpVoid;
int c = *b;
free(lpVoid);
return 0;
}
DWORD WINAPI MyThread1(LPVOID lpVoid)
{
int count =100;
while(count)
{
int* a = NULL;
a= (int*)malloc(sizeof(int));
*a = count;
CloseHandle(CreateThread(NULL, 0, MyThread2,(LPVOID)a, 0, NULL));
count --;
}
return 0;
}
int main()
{
CreateThread(NULL, 0, MyThread1,NULL, 0, NULL);
// wait here until MyThread1 exits.
return 0;
}