2 * Copyright (c) 2000-2001, 2006 Proofpoint, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
9 * $Id: heap.h,v 1.24 2013-11-22 20:51:31 ca Exp $
13 ** Sendmail debugging memory allocation package.
14 ** See libsm/heap.html for documentation.
22 # include <sm/debug.h>
25 /* change default to 0 for production? */
26 # ifndef SM_HEAP_CHECK
27 # define SM_HEAP_CHECK 1
31 # define sm_malloc_x(sz) sm_malloc_tagged_x(sz, __FILE__, __LINE__, SmHeapGroup)
32 # define sm_malloc(size) sm_malloc_tagged(size, __FILE__, __LINE__, SmHeapGroup)
33 # define sm_free(ptr) sm_free_tagged(ptr, __FILE__, __LINE__)
35 extern void *sm_malloc_tagged __P((size_t, char *, int, int));
36 extern void *sm_malloc_tagged_x __P((size_t, char *, int, int));
37 extern void sm_free_tagged __P((void *, char *, int));
38 extern void *sm_realloc_x __P((void *, size_t));
39 extern bool sm_heap_register __P((void *, size_t, char *, int, int));
40 extern void sm_heap_checkptr_tagged __P((void *, char *, int));
41 extern void sm_heap_report __P((SM_FILE_T *, int));
43 # else /* SM_HEAP_CHECK */
44 # define sm_malloc_tagged(size, file, line, grp) sm_malloc(size)
45 # define sm_malloc_tagged_x(size, file, line, grp) sm_malloc_x(size)
46 # define sm_free_tagged(ptr, file, line) sm_free(ptr)
47 # define sm_heap_register(ptr, size, file, line, grp) (true)
48 # define sm_heap_checkptr_tagged(ptr, tag, num) ((void)0)
49 # define sm_heap_report(file, verbose) ((void)0)
51 extern void *sm_malloc __P((size_t));
52 extern void *sm_malloc_x __P((size_t));
53 extern void *sm_realloc_x __P((void *, size_t));
54 extern void sm_free __P((void *));
55 # endif /* SM_HEAP_CHECK */
57 extern void *sm_realloc __P((void *, size_t));
59 # define sm_heap_checkptr(ptr) sm_heap_checkptr_tagged(ptr, __FILE__, __LINE__)
63 ** sm_f[mc]alloc are plug in replacements for malloc and calloc
64 ** which can be used in a context requiring a function pointer,
65 ** and which are compatible with sm_free. Warning: sm_heap_report
66 ** cannot report where storage leaked by sm_f[mc]alloc was allocated.
69 /* XXX unused right now */
82 ** Allocate 'permanent' storage that can be freed but may still be
83 ** allocated when the process exits. sm_heap_report will not complain
84 ** about a storage leak originating from a call to sm_pmalloc.
87 # define sm_pmalloc(size) sm_malloc_tagged(size, __FILE__, __LINE__, 0)
88 # define sm_pmalloc_x(size) sm_malloc_tagged_x(size, __FILE__, __LINE__, 0)
90 # define sm_heap_group() SmHeapGroup
91 # define sm_heap_setgroup(g) (SmHeapGroup = (g))
92 # define sm_heap_newgroup() (SmHeapGroup = ++SmHeapMaxGroup)
94 #define SM_FREE(ptr) \
104 extern int SmHeapGroup;
105 extern int SmHeapMaxGroup;
107 extern SM_DEBUG_T SmHeapTrace;
108 extern SM_DEBUG_T SmHeapCheck;
109 extern SM_EXC_T SmHeapOutOfMemory;
111 #endif /* ! SM_HEAP_H */