struct Test char 100 char CRITICAL_SECTION cs void func_useDeletedMemo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
struct Test
{
char t[100];
char* p;
CRITICAL_SECTION cs;
};
void func_useDeletedMemory()
{
printf("func_useDeletedMemory");
Test* t = new Test;
t->p = new char[100];
delete t;
delete []t->p;
}
void func_deleteMemoryWithCriticalSection()
{
printf("func_deleteMemoryWithCriticalSection");
Test* t = new Test;
InitializeCriticalSection(&t->cs);
delete t;
}
int _tmain(int argc, _TCHAR* argv[])
{
if (argc < 2)
func_useDeletedMemory();
else
func_deleteMemoryWithCriticalSection();
return 0;
}