aboutsummaryrefslogtreecommitdiff
path: root/contrib/sendmail/libsm/t-heap.c
blob: 05811bb579defe297d23324bdbb71b0c1eb25936 (plain) (blame)
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
/*
 * Copyright (c) 2000-2001 Sendmail, 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.
 */

#include <sm/gen.h>
SM_IDSTR(id, "@(#)$Id: t-heap.c,v 1.1.1.1 2002/02/17 21:56:43 gshapiro Exp $")

#include <sm/debug.h>
#include <sm/heap.h>
#include <sm/io.h>
#include <sm/test.h>
#include <sm/xtrap.h>

#if SM_HEAP_CHECK
extern SM_DEBUG_T SmHeapCheck;
# define HEAP_CHECK sm_debug_active(&SmHeapCheck, 1)
#else /* SM_HEAP_CHECK */
# define HEAP_CHECK 0
#endif /* SM_HEAP_CHECK */

int
main(argc, argv)
	int argc;
	char **argv;
{
	void *p;

	sm_test_begin(argc, argv, "test heap handling");
	if (argc > 1)
		sm_debug_addsettings_x(argv[1]);

	p = sm_malloc(10);
	SM_TEST(p != NULL);
	p = sm_realloc_x(p, 20);
	SM_TEST(p != NULL);
	p = sm_realloc(p, 30);
	SM_TEST(p != NULL);
	if (HEAP_CHECK)
	{
		sm_dprintf("heap with 1 30-byte block allocated:\n");
		sm_heap_report(smioout, 3);
	}

	if (HEAP_CHECK)
	{
		sm_free(p);
		sm_dprintf("heap with 0 blocks allocated:\n");
		sm_heap_report(smioout, 3);
		sm_dprintf("xtrap count = %d\n", SmXtrapCount);
	}

#if DEBUG
	/* this will cause a core dump */
	sm_dprintf("about to free %p for the second time\n", p);
	sm_free(p);
#endif /* DEBUG */

	return sm_test_end();
}