1 /* 2 * 3 * This file is part of the XForms library package. 4 * 5 * XForms is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU Lesser General Public License as 7 * published by the Free Software Foundation; either version 2.1, or 8 * (at your option) any later version. 9 * 10 * XForms is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with XForms. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 20 /** 21 * \file dmalloc.h 22 * 23 * This file is part of the XForms library package. 24 * Copyright (c) 1996-1998 T.C. Zhao and Mark Overmars 25 * All rights reserved. 26 * 27 * Very simple debug version of malloc family. It works by replacing the 28 * standard malloc and its cousins with my own routines that track, among 29 * other things, where mallocs are called and how many bytes they get. All 30 * these relies on the the work of true malloc. A true debug version of 31 * malloc should replace malloc with calls to sbrk. Anyway, All I want out of 32 * this hack is to make sure there are no memory leaks. 33 */ 34 35 #ifndef TC_DMALLOC_H_ 36 #define TC_DMALLOC_H_ 37 38 #include <stdlib.h> 39 40 #ifdef TC_MEMDBG 41 42 extern void *tc_dbg_malloc( size_t, 43 const char *, 44 int ); 45 extern void *tc_dbg_calloc( size_t, 46 size_t, 47 const char *, 48 int ); 49 extern void *tc_dbg_realloc( void *, 50 size_t, 51 const char *, 52 int ); 53 extern void *tc_dbg_getmat( int, 54 int, 55 size_t, 56 const char *, 57 int ); 58 extern char *tc_dbg_strdup( const char *, 59 const char *, 60 int ); 61 extern void tc_dbg_free( void *, 62 const char *, 63 int ); 64 extern void tc_true_free( void * ); 65 extern void tc_set_mem_warn( int ); 66 extern void tc_mem_stat( int ); 67 68 #ifndef TC_MEMDBG_OWNER /* actual replacememnt */ 69 #define fl_malloc( a ) tc_dbg_malloc( a, __FILE__, __LINE__ ) 70 #define fl_calloc( a, b ) tc_dbg_calloc( a, b, __FILE__, __LINE__ ) 71 #define fl_realloc( a, b ) tc_dbg_realloc( a, b, __FILE__, __LINE__ ) 72 #define fl_free( a ) tc_dbg_free( a, __FILE__, __LINE__ ) 73 #define fl_strdup( a ) tc_dbg_strdup( a, __FILE__, __LINE__ ) 74 #endif /* TC_MEMDBG_OWNER */ 75 76 #else /* if not debug, tfree becomes free */ 77 78 #ifndef fl_free 79 #define fl_malloc( a ) malloc( a ) 80 #define fl_calloc( a, b ) calloc( a, b ) 81 #define fl_realloc( a, b ) realloc( a, b ) 82 #define fl_free( a ) free( a ) 83 #endif 84 85 #define tc_true_free( p ) free( p ) 86 #define tc_mem_stat( a ) 87 #define tc_set_mem_warn( p ) 88 89 #endif /* TC_MEMDBG */ 90 91 #endif /* _MY_MALLOC_H */ 92 93 94 /* 95 * Local variables: 96 * tab-width: 4 97 * indent-tabs-mode: nil 98 * End: 99 */ 100