1 /* $Id: misc.c,v 1.2.2.1 1999/02/19 15:24:15 ben Exp $ */
7 /* My own versions of malloc, realloc and free. Because I want malloc and
8 * realloc to bomb out and exit the program if they run out of memory,
9 * realloc to reliably call malloc if passed a NULL pointer, and free
10 * to reliably do nothing if passed a NULL pointer. Of course we can also
11 * put trace printouts in, if we need to. */
14 static FILE *fp = NULL;
16 void mlog(char *file, int line) {
18 fp = fopen("putty_mem.log", "w");
19 setvbuf(fp, NULL, _IONBF, BUFSIZ);
22 fprintf (fp, "%s:%d: ", file, line);
26 void *safemalloc(size_t size) {
27 void *p = malloc (size);
29 fatalbox("%s", "Out of memory!");
32 fprintf(fp, "malloc(%d) returns %p\n", size, p);
37 void *saferealloc(void *ptr, size_t size) {
42 p = realloc (ptr, size);
44 fatalbox("%s", "Out of memory!");
47 fprintf(fp, "realloc(%p,%d) returns %p\n", ptr, size, p);
52 void safefree(void *ptr) {
56 fprintf(fp, "free(%p)\n", ptr);
62 fprintf(fp, "freeing null pointer - no action taken\n");