2 * PuTTY memory-handling header.
5 #ifndef PUTTY_PUTTYMEM_H
6 #define PUTTY_PUTTYMEM_H
8 #include <stddef.h> /* for size_t */
9 #include <string.h> /* for memcpy() */
12 /* #define MALLOC_LOG do this if you suspect putty of leaking memory */
14 #define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z))
15 #define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z))
16 #define sfree(z) (mlog(__FILE__,__LINE__), safefree(z))
17 void mlog(char *, int);
19 #define smalloc safemalloc
20 #define srealloc saferealloc
21 #define sfree safefree
24 void *safemalloc(size_t);
25 void *saferealloc(void *, size_t);
26 void safefree(void *);
29 * Direct use of smalloc within the code should be avoided where
30 * possible, in favour of these type-casting macros which ensure
31 * you don't mistakenly allocate enough space for one sort of
32 * structure and assign it to a different sort of pointer.
34 #define snew(type) ((type *)smalloc(sizeof(type)))
35 #define snewn(n, type) ((type *)smalloc((n)*sizeof(type)))
36 #define sresize(ptr, n, type) ((type *)srealloc(ptr, (n)*sizeof(type)))