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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#include "commonheaders.h"
/*
void m_check(void *ptr, const char *module) {
if(ptr==NULL) {
char buffer[128];
strcpy(buffer,module); strcat(buffer,": NULL pointer detected !");
MessageBoxA(0,buffer,szModuleName,MB_OK|MB_ICONSTOP);
__asm{ int 3 };
exit(1);
}
}
void *m_alloc(size_t size) {
void *ptr;
ptr = malloc(size);
m_check(ptr,"m_alloc");
ZeroMemory(ptr,size);
return ptr;
}
void m_free(void *ptr) {
// m_check(ptr,"m_free");
if(ptr) {
free(ptr);
}
}
void *m_realloc(void *ptr,size_t size) {
r = realloc(ptr,size);
m_check(ptr,"m_realloc");
return ptr;
}
#ifndef _DEBUG
void *operator new(size_t size) {
return malloc(size);
}
#endif
void operator delete(void *p) {
free(p);
}
void *operator new[](size_t size) {
return operator new(size);
}
void operator delete[](void *p) {
operator delete(p);
}
char *m_strdup(const char *str) {
if(str==NULL) return NULL;
int len = (int)strlen(str)+1;
char *dup = (char*) m_alloc(len);
MoveMemory((void*)dup,(void*)str,len);
return dup;
}
*/
void __fastcall safe_free(void** p)
{
if (*p) {
free(*p);
*p = NULL;
}
}
void __fastcall safe_delete(void** p)
{
if (*p) {
delete(*p);
*p = NULL;
}
}
// EOF
|