13 /* My own versions of malloc, realloc and free. Because I want malloc and
14 * realloc to bomb out and exit the program if they run out of memory,
15 * realloc to reliably call malloc if passed a NULL pointer, and free
16 * to reliably do nothing if passed a NULL pointer. Of course we can also
17 * put trace printouts in, if we need to. */
20 static FILE *fp
= NULL
;
22 void mlog(char *file
, int line
) {
24 fp
= fopen("putty_mem.log", "w");
25 setvbuf(fp
, NULL
, _IONBF
, BUFSIZ
);
28 fprintf (fp
, "%s:%d: ", file
, line
);
32 void *safemalloc(size_t size
) {
33 void *p
= malloc (size
);
35 MessageBox(NULL
, "Out of memory!", "PuTTY Fatal Error",
36 MB_SYSTEMMODAL
| MB_ICONERROR
| MB_OK
);
41 fprintf(fp
, "malloc(%d) returns %p\n", size
, p
);
46 void *saferealloc(void *ptr
, size_t size
) {
51 p
= realloc (ptr
, size
);
53 MessageBox(NULL
, "Out of memory!", "PuTTY Fatal Error",
54 MB_SYSTEMMODAL
| MB_ICONERROR
| MB_OK
);
59 fprintf(fp
, "realloc(%p,%d) returns %p\n", ptr
, size
, p
);
64 void safefree(void *ptr
) {
68 fprintf(fp
, "free(%p)\n", ptr
);
74 fprintf(fp
, "freeing null pointer - no action taken\n");