1 /*
2  *
3  * XASTIR, Amateur Station Tracking and Information Reporting
4  * Copyright (C) 2000-2019 The Xastir Group
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * Look at the README for more information on the program.
21  */
22 
23 /* All of the misc entry points to be included for all packages */
24 
25 #ifndef _LEAK_DETECTION_H
26 #define _LEAK_DETECTION_H
27 
28 
29 // If libgc is installed, uncomment this next line to enable memory
30 // leak detection:
31 #define DETECT_MEMORY_LEAKS
32 
33 
34 // Defines for including the libgc garbage collection library.
35 // This enables automatic garbage collection of unused memory,
36 // very similar to the garbage collection in Java.  Get libgc from
37 // here:  http://www.hpl.hp.com/personal/Hans_Boehm/gc/
38 //
39 // This will cause stats to be printed every 60 seconds, 'cuz we
40 // call GC_collect via a macro from UpdateTime() once per minute:
41 // export GC_PRINT_STATS=1; xastir &
42 //
43 // Compile libgc with this option for more debugging output.  I
44 // didn't do so:  --enable-full_debug
45 //
46 // If we enable these thread options, Xastir won't link with the
47 // library.  Since we don't allocate dynamic memory in the child
48 // threads anyway, skip them.
49 // --enable-threads=posix --enable-thread-local-alloc --enable-parallel-mark
50 //
51 // Call GC_gcollect at appropriate points to check for leaks.  We do
52 // this via the CHECK_LEAKS macro called from main.c:UpdateTime.
53 //
54 //
55 // Note:  The thread includes must be done before the libgc includes
56 // as libgc redefines some thread stuff so that it cooperates with
57 // the garbage collector routines.  Any code module that does
58 // malloc's/free's or thread operations should include
59 // leak_detection.h as the last include if at all possible, and
60 // should not include pthread.h themselves.
61 //
62 #include <pthread.h>
63 #include <stdlib.h> /* Where malloc/free definitions reside */
64 #ifdef HAVE_DMALLOC
65   #include <dmalloc.h>
66 #endif  // HAVE_DMALLOC
67 //
68 #ifdef HAVE_GC_H
69   #ifdef HAVE_LIBGC
70 
71     // We use this define to enable code in *.c files
72     #define USING_LIBGC
73 
74     // Set up for threads
75     #define GC_THREADS
76 
77     #ifdef __LINUX__
78       #define GC_LINUX_THREADS
79     #endif  // __LINUX__
80 
81     //    #define _REENTRANT
82 
83     // Ask for more debugging
84     #define GC_DEBUG
85 
86     #include <gc.h>
87     #define malloc(n) GC_MALLOC(n)
88     #define calloc(m,n) GC_MALLOC((m)*(n))
89     #define free(p) GC_FREE(p)
90     #define realloc(p,n) GC_REALLOC((p),(n))
91     #define CHECK_LEAKS() GC_gcollect()
92 
93   #endif    // HAVE_LIBGC
94 #endif  // HAVE_GC_H
95 
96 
97 
98 #endif /* LEAK_DETECTION_H */
99 
100 
101