OpenVPN
memdbg.h
Go to the documentation of this file.
1 /*
2  * OpenVPN -- An application to securely tunnel IP networks
3  * over a single UDP port, with support for SSL/TLS-based
4  * session authentication and key exchange,
5  * packet encryption, packet authentication, and
6  * packet compression.
7  *
8  * Copyright (C) 2002-2018 OpenVPN Inc <sales@openvpn.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2
12  * as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef MEMDBG_H
25 #define MEMDBG_H
26 
27 /*
28  * Valgrind debugging support.
29  *
30  * Valgrind is a great tool for debugging memory issues,
31  * though it seems to generate a lot of warnings in OpenSSL
32  * about uninitialized data. To silence these warnings,
33  * I've put together a suppressions file
34  * in debug/valgrind-suppress.
35  *
36  * Also, grep for VALGRIND_MAKE_READABLE in the OpenVPN source.
37  * Because valgrind thinks that some of the data passed from
38  * OpenSSL back to OpenVPN is tainted due to being sourced
39  * from uninitialized data, we need to untaint it before use --
40  * otherwise we will get a lot of useless warnings.
41  *
42  * valgrind --tool=memcheck --error-limit=no --suppressions=debug/valgrind-suppress --gen-suppressions=yes ./openvpn ...
43  */
44 
45 #ifdef USE_VALGRIND
46 
47 #include <valgrind/memcheck.h>
48 
49 #define VALGRIND_MAKE_READABLE(addr, len)
50 
51 #else /* ifdef USE_VALGRIND */
52 
53 #define VALGRIND_MAKE_READABLE(addr, len)
54 
55 #endif
56 
57 #ifdef DMALLOC /* see ./configure options to enable */
58 
59 /*
60  * See ./configure options to enable dmalloc
61  * support for memory leak checking.
62  *
63  * The dmalloc package can be downloaded from:
64  *
65  * http://dmalloc.com/
66  *
67  * When dmalloc is installed and enabled,
68  * use this command prior to running openvpn:
69  *
70  * dmalloc -l dlog -i 100 low -p log-unknown
71  *
72  * Also, put this in your .bashrc file:
73  *
74  * function dmalloc { eval `command dmalloc -b $*`; }
75  *
76  * Or take a more low-level approach:
77  *
78  * export DMALLOC_OPTIONS="debug=0x4e48503,inter=100,log=dlog"
79  *
80  * NOTE: When building dmalloc you need to add something
81  * like this to dmalloc's settings.h -- it will allocate a static
82  * buffer to be used as the malloc arena:
83  *
84  * #define INTERNAL_MEMORY_SPACE (1024 * 1024 * 50)
85  */
86 
87 #include <dmalloc.h>
88 
89 #define openvpn_dmalloc(file, line, size) dmalloc_malloc((file), (line), (size), DMALLOC_FUNC_MALLOC, 0, 0)
90 
91 /*
92  * This #define will put the line number of the log
93  * file position where leaked memory was allocated instead
94  * of the source code file and line number. Make sure
95  * to increase the size of dmalloc's info tables,
96  * (MEMORY_TABLE_SIZE in settings.h)
97  * otherwise it might get overwhelmed by the large
98  * number of unique file/line combinations.
99  */
100 #if 0
101 #undef malloc
102 #define malloc(size) openvpn_dmalloc("logfile", x_msg_line_num, (size))
103 #endif
104 
105 #endif /* DMALLOC */
106 
107 /*
108  * Force buffers to be zeroed after allocation.
109  * For debugging only.
110  */
111 /*#define ZERO_BUFFER_ON_ALLOC*/
112 
113 #endif /* MEMDBG_H */