Correct some comments based on feedback from Thomas Dickey.
[u/mdw/putty] / puttymem.h
CommitLineData
dcbde236 1/*
2 * PuTTY memory-handling header.
3 */
4
5#ifndef PUTTY_PUTTYMEM_H
6#define PUTTY_PUTTYMEM_H
7
32874aea 8#include <stddef.h> /* for size_t */
9#include <string.h> /* for memcpy() */
db9c0f86 10
11
dcbde236 12/* #define MALLOC_LOG do this if you suspect putty of leaking memory */
13#ifdef MALLOC_LOG
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))
17void mlog(char *, int);
18#else
19#define smalloc safemalloc
20#define srealloc saferealloc
21#define sfree safefree
22#endif
23
24void *safemalloc(size_t);
25void *saferealloc(void *, size_t);
26void safefree(void *);
27
3d88e64d 28/*
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.
33 */
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)))
db9c0f86 37
dcbde236 38#endif