t-heap.c revision 363466
1104349Sphk/* 2104349Sphk * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers. 3104349Sphk * All rights reserved. 4104349Sphk * 5104349Sphk * By using this file, you agree to the terms and conditions set 6104349Sphk * forth in the LICENSE file which can be found at the top level of 7104349Sphk * the sendmail distribution. 8104349Sphk */ 9104349Sphk 10104349Sphk#include <sm/gen.h> 11104349SphkSM_IDSTR(id, "@(#)$Id: t-heap.c,v 1.11 2013-11-22 20:51:43 ca Exp $") 12104349Sphk 13104349Sphk#include <sm/debug.h> 14104349Sphk#include <sm/heap.h> 15104349Sphk#include <sm/io.h> 16104349Sphk#include <sm/test.h> 17104349Sphk#include <sm/xtrap.h> 18 19#if SM_HEAP_CHECK 20extern SM_DEBUG_T SmHeapCheck; 21# define HEAP_CHECK sm_debug_active(&SmHeapCheck, 1) 22#else 23# define HEAP_CHECK 0 24#endif /* SM_HEAP_CHECK */ 25 26int 27main(argc, argv) 28 int argc; 29 char **argv; 30{ 31 void *p; 32 33 sm_test_begin(argc, argv, "test heap handling"); 34 if (argc > 1) 35 sm_debug_addsettings_x(argv[1]); 36 37 p = sm_malloc(10); 38 SM_TEST(p != NULL); 39 p = sm_realloc_x(p, 20); 40 SM_TEST(p != NULL); 41 p = sm_realloc(p, 30); 42 SM_TEST(p != NULL); 43 if (HEAP_CHECK) 44 { 45 sm_dprintf("heap with 1 30-byte block allocated:\n"); 46 sm_heap_report(smioout, 3); 47 } 48 49 if (HEAP_CHECK) 50 { 51 sm_free(p); 52 sm_dprintf("heap with 0 blocks allocated:\n"); 53 sm_heap_report(smioout, 3); 54 sm_dprintf("xtrap count = %d\n", SmXtrapCount); 55 } 56 57#if DEBUG 58 /* this will cause a core dump */ 59 sm_dprintf("about to free %p for the second time\n", p); 60 sm_free(p); 61#endif 62 63 return sm_test_end(); 64} 65