t-heap.c revision 261194
1254721Semaste/* 2254721Semaste * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers. 3254721Semaste * All rights reserved. 4254721Semaste * 5254721Semaste * By using this file, you agree to the terms and conditions set 6254721Semaste * forth in the LICENSE file which can be found at the top level of 7254721Semaste * the sendmail distribution. 8254721Semaste */ 9254721Semaste 10254721Semaste#include <sm/gen.h> 11254721SemasteSM_IDSTR(id, "@(#)$Id: t-heap.c,v 1.11 2013/11/22 20:51:43 ca Exp $") 12254721Semaste 13254721Semaste#include <sm/debug.h> 14254721Semaste#include <sm/heap.h> 15254721Semaste#include <sm/io.h> 16254721Semaste#include <sm/test.h> 17254721Semaste#include <sm/xtrap.h> 18254721Semaste 19254721Semaste#if SM_HEAP_CHECK 20254721Semasteextern SM_DEBUG_T SmHeapCheck; 21254721Semaste# define HEAP_CHECK sm_debug_active(&SmHeapCheck, 1) 22254721Semaste#else /* SM_HEAP_CHECK */ 23254721Semaste# define HEAP_CHECK 0 24254721Semaste#endif /* SM_HEAP_CHECK */ 25254721Semaste 26254721Semasteint 27254721Semastemain(argc, argv) 28254721Semaste int argc; 29254721Semaste char **argv; 30254721Semaste{ 31254721Semaste void *p; 32254721Semaste 33254721Semaste sm_test_begin(argc, argv, "test heap handling"); 34254721Semaste if (argc > 1) 35254721Semaste sm_debug_addsettings_x(argv[1]); 36254721Semaste 37254721Semaste p = sm_malloc(10); 38254721Semaste SM_TEST(p != NULL); 39254721Semaste p = sm_realloc_x(p, 20); 40254721Semaste SM_TEST(p != NULL); 41254721Semaste p = sm_realloc(p, 30); 42254721Semaste SM_TEST(p != NULL); 43254721Semaste if (HEAP_CHECK) 44254721Semaste { 45254721Semaste sm_dprintf("heap with 1 30-byte block allocated:\n"); 46254721Semaste sm_heap_report(smioout, 3); 47254721Semaste } 48254721Semaste 49254721Semaste if (HEAP_CHECK) 50262528Semaste { 51254721Semaste sm_free(p); 52254721Semaste sm_dprintf("heap with 0 blocks allocated:\n"); 53254721Semaste sm_heap_report(smioout, 3); 54254721Semaste sm_dprintf("xtrap count = %d\n", SmXtrapCount); 55262528Semaste } 56254721Semaste 57254721Semaste#if DEBUG 58254721Semaste /* this will cause a core dump */ 59254721Semaste sm_dprintf("about to free %p for the second time\n", p); 60254721Semaste sm_free(p); 61262528Semaste#endif /* DEBUG */ 62262528Semaste 63262528Semaste return sm_test_end(); 64262528Semaste} 65262528Semaste