File: heap.h

package info (click to toggle)
sendmail 8.18.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,268 kB
  • sloc: ansic: 106,906; perl: 7,504; sh: 5,488; makefile: 888
file content (91 lines) | stat: -rw-r--r-- 2,844 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Copyright (c) 2000-2001, 2006 Proofpoint, Inc. and its suppliers.
 *	All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at the top level of
 * the sendmail distribution.
 *
 *	$Id: heap.h,v 1.24 2013-11-22 20:51:31 ca Exp $
 */

/*
**  Sendmail debugging memory allocation package.
**  See libsm/heap.html for documentation.
*/

#ifndef SM_HEAP_H
# define SM_HEAP_H

# include <sm/io.h>
# include <stdlib.h>
# include <sm/debug.h>
# include <sm/exc.h>

/* change default to 0 for production? */
# ifndef SM_HEAP_CHECK
#  define SM_HEAP_CHECK		1
# endif

# if SM_HEAP_CHECK
#  define sm_malloc_x(sz) sm_malloc_tagged_x(sz, __FILE__, __LINE__, SmHeapGroup)
#  define sm_malloc(size) sm_malloc_tagged(size, __FILE__, __LINE__, SmHeapGroup)
#  define sm_free(ptr) sm_free_tagged(ptr, __FILE__, __LINE__)

extern void *sm_malloc_tagged __P((size_t, char *, int, int));
extern void *sm_malloc_tagged_x __P((size_t, char *, int, int));
extern void sm_free_tagged __P((void *, char *, int));
extern void *sm_realloc_x __P((void *, size_t));
extern bool sm_heap_register __P((void *, size_t, char *, int, int));
extern void sm_heap_checkptr_tagged  __P((void *, char *, int));
extern void sm_heap_report __P((SM_FILE_T *, int));

# else /* SM_HEAP_CHECK */
#  define sm_malloc_tagged(size, file, line, grp)	sm_malloc(size)
#  define sm_malloc_tagged_x(size, file, line, grp)	sm_malloc_x(size)
#  define sm_free_tagged(ptr, file, line)		sm_free(ptr)
#  define sm_heap_register(ptr, size, file, line, grp)	(true)
#  define sm_heap_checkptr_tagged(ptr, tag, num)	((void)0)
#  define sm_heap_report(file, verbose)			((void)0)

extern void *sm_malloc __P((size_t));
extern void *sm_malloc_x __P((size_t));
extern void *sm_realloc_x __P((void *, size_t));
extern void sm_free __P((void *));
# endif /* SM_HEAP_CHECK */

extern void *sm_realloc __P((void *, size_t));

# define sm_heap_checkptr(ptr) sm_heap_checkptr_tagged(ptr, __FILE__, __LINE__)

/*
**  Allocate 'permanent' storage that can be freed but may still be
**  allocated when the process exits.  sm_heap_report will not complain
**  about a storage leak originating from a call to sm_pmalloc.
*/

# define sm_pmalloc(size)   sm_malloc_tagged(size, __FILE__, __LINE__, 0)
# define sm_pmalloc_x(size) sm_malloc_tagged_x(size, __FILE__, __LINE__, 0)

# define sm_heap_group()	SmHeapGroup
# define sm_heap_setgroup(g)	(SmHeapGroup = (g))
# define sm_heap_newgroup()	(SmHeapGroup = ++SmHeapMaxGroup)

#define SM_FREE(ptr)			\
	do				\
	{				\
		if ((ptr) != NULL)	\
		{			\
			sm_free(ptr);	\
			(ptr) = NULL;	\
		}			\
	} while (0)

extern int SmHeapGroup;
extern int SmHeapMaxGroup;

extern SM_DEBUG_T SmHeapTrace;
extern SM_DEBUG_T SmHeapCheck;
extern SM_EXC_T SmHeapOutOfMemory;

#endif /* ! SM_HEAP_H */