xref: /titanic_41/usr/src/cmd/sendmail/libsm/t-heap.c (revision 9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bb)
1 /*
2  * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3  *	All rights reserved.
4  *
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.
8  */
9 
10 #pragma ident	"%Z%%M%	%I%	%E% SMI"
11 
12 #include <sm/gen.h>
13 SM_IDSTR(id, "@(#)$Id: t-heap.c,v 1.8 2001/03/06 17:27:36 ca Exp $")
14 
15 #include <sm/debug.h>
16 #include <sm/heap.h>
17 #include <sm/io.h>
18 #include <sm/test.h>
19 #include <sm/xtrap.h>
20 
21 #if SM_HEAP_CHECK
22 extern SM_DEBUG_T SmHeapCheck;
23 # define HEAP_CHECK sm_debug_active(&SmHeapCheck, 1)
24 #else /* SM_HEAP_CHECK */
25 # define HEAP_CHECK 0
26 #endif /* SM_HEAP_CHECK */
27 
28 int
29 main(argc, argv)
30 	int argc;
31 	char **argv;
32 {
33 	void *p;
34 
35 	sm_test_begin(argc, argv, "test heap handling");
36 	if (argc > 1)
37 		sm_debug_addsettings_x(argv[1]);
38 
39 	p = sm_malloc(10);
40 	SM_TEST(p != NULL);
41 	p = sm_realloc_x(p, 20);
42 	SM_TEST(p != NULL);
43 	p = sm_realloc(p, 30);
44 	SM_TEST(p != NULL);
45 	if (HEAP_CHECK)
46 	{
47 		sm_dprintf("heap with 1 30-byte block allocated:\n");
48 		sm_heap_report(smioout, 3);
49 	}
50 
51 	if (HEAP_CHECK)
52 	{
53 		sm_free(p);
54 		sm_dprintf("heap with 0 blocks allocated:\n");
55 		sm_heap_report(smioout, 3);
56 		sm_dprintf("xtrap count = %d\n", SmXtrapCount);
57 	}
58 
59 #if DEBUG
60 	/* this will cause a core dump */
61 	sm_dprintf("about to free %p for the second time\n", p);
62 	sm_free(p);
63 #endif /* DEBUG */
64 
65 	return sm_test_end();
66 }
67