]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Remove --with-mem-check=dmalloc
authorFrank Lichtenheld <frank@lichtenheld.com>
Fri, 7 Aug 2026 13:15:39 +0000 (15:15 +0200)
committerGert Doering <gert@greenie.muc.de>
Sun, 9 Aug 2026 08:32:15 +0000 (10:32 +0200)
This code hasn't compiled for years and noone complained.
We generally use ASAN instead.

So remove the dead code.

v2: The first version of this change tried to fix the
    code. v2 instead removes it.

Change-Id: I4920318ac537064508eee3ca449d48de76c2ea5d
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1582
Message-Id: <20260807131539.53877-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg38208.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
CMakeLists.txt
config.h.cmake.in
configure.ac
src/openvpn/buffer.c
src/openvpn/buffer.h
src/openvpn/crypto_backend.h
src/openvpn/crypto_mbedtls_legacy.c
src/openvpn/crypto_openssl.c
src/openvpn/init.c
src/openvpn/memdbg.h

index aabbcb67cf03907f489fc9aa42a9c8dc2ba33a0c..643dec6c42abe33241528859ff167ff5210405b2 100644 (file)
@@ -260,7 +260,6 @@ endif ()
 
 check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
 check_include_files(dlfcn.h HAVE_DLFCN_H)
-check_include_files(dmalloc.h HAVE_DMALLOC_H)
 check_include_files(fcntl.h HAVE_FCNTL_H)
 check_include_files(err.h HAVE_ERR_H)
 check_include_files(netdb.h HAVE_NETDB_H)
index 34f289dbabd47b85ec9ac98bb2367a5822baf1ef..c3bb5a55abf68b2b6bb5438689b4d6fce6f021ab 100644 (file)
@@ -96,9 +96,6 @@
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #cmakedefine HAVE_DLFCN_H
 
-/* Define to 1 if you have the <dmalloc.h> header file. */
-#cmakedefine HAVE_DMALLOC_H
-
 /* Define to 1 if you have the `dup' function. */
 #cmakedefine HAVE_DUP
 
index 1aec8053f5d64fed13aaca58ff0507a154579f69..469a475b9aab00ef943b6e0ab3076c444c5ca17c 100644 (file)
@@ -245,10 +245,10 @@ AC_ARG_WITH(
 
 AC_ARG_WITH(
        [mem-check],
-       [AS_HELP_STRING([--with-mem-check=TYPE], [build with debug memory checking, TYPE=no|dmalloc|valgrind|ssl @<:@default=no@:>@])],
+       [AS_HELP_STRING([--with-mem-check=TYPE], [build with debug memory checking, TYPE=no|valgrind|ssl @<:@default=no@:>@])],
        [
                case "${withval}" in
-                       dmalloc|valgrind|ssl|no) ;;
+                       valgrind|ssl|no) ;;
                        *) AC_MSG_ERROR([bad value ${withval} for --mem-check]) ;;
                esac
        ],
@@ -652,25 +652,6 @@ case "${with_mem_check}" in
                        [AC_MSG_ERROR([valgrind headers not found.])]
                )
                ;;
-       dmalloc)
-               AC_CHECK_HEADERS(
-                       [dmalloc.h],
-                       [AC_CHECK_LIB(
-                               [dmalloc],
-                               [malloc],
-                               [
-                                       LIBS="${LIBS} -ldmalloc"
-                                       AC_DEFINE(
-                                               [DMALLOC],
-                                               [1],
-                                               [Use dmalloc memory debugging library]
-                                       )
-                               ],
-                               [AC_MSG_ERROR([dmalloc library not found.])]
-                       )],
-                       [AC_MSG_ERROR([dmalloc headers not found.])]
-               )
-               ;;
        ssl)
                AC_CHECK_LIB(
                        [ssl],
index 922238df1a03824851c0a8570f41ad8ca9627667..f14caa2d3ed18c94323783fcc455bf61d95a504e 100644 (file)
@@ -57,11 +57,7 @@ buf_size_error(const size_t size)
 }
 
 struct buffer
-#ifdef DMALLOC
-alloc_buf_debug(size_t size, const char *file, int line)
-#else
 alloc_buf(size_t size)
-#endif
 {
     struct buffer buf;
     CLEAR(buf);
@@ -71,22 +67,14 @@ alloc_buf(size_t size)
         buf_size_error(size);
     }
     buf.capacity = (int)size;
-#ifdef DMALLOC
-    buf.data = openvpn_dmalloc(file, line, size);
-#else
     buf.data = calloc(1, size);
-#endif
     check_malloc_return(buf.data);
 
     return buf;
 }
 
 struct buffer
-#ifdef DMALLOC
-alloc_buf_gc_debug(size_t size, struct gc_arena *gc, const char *file, int line)
-#else
 alloc_buf_gc(size_t size, struct gc_arena *gc)
-#endif
 {
     struct buffer buf;
     CLEAR(buf);
@@ -96,11 +84,7 @@ alloc_buf_gc(size_t size, struct gc_arena *gc)
         buf_size_error(size);
     }
     buf.capacity = (int)size;
-#ifdef DMALLOC
-    buf.data = (uint8_t *)gc_malloc_debug(size, false, gc, file, line);
-#else
     buf.data = (uint8_t *)gc_malloc(size, false, gc);
-#endif
     if (size)
     {
         *buf.data = 0;
@@ -109,7 +93,7 @@ alloc_buf_gc(size_t size, struct gc_arena *gc)
 }
 
 struct buffer
-#ifdef DMALLOC
+#ifdef BUF_INIT_TRACKING
 clone_buf_debug(const struct buffer *buf, const char *file, int line)
 #else
 clone_buf(const struct buffer *buf)
@@ -123,11 +107,7 @@ clone_buf(const struct buffer *buf)
     ret.debug_file = buf->debug_file;
     ret.debug_line = buf->debug_line;
 #endif
-#ifdef DMALLOC
-    ret.data = (uint8_t *)openvpn_dmalloc(file, line, buf->capacity);
-#else
     ret.data = (uint8_t *)malloc(buf->capacity);
-#endif
     check_malloc_return(ret.data);
     memcpy(BPTR(&ret), BPTR(buf), BLENZ(buf));
     return ret;
@@ -335,21 +315,13 @@ cleanup:
  */
 
 void *
-#ifdef DMALLOC
-gc_malloc_debug(size_t size, bool clear, struct gc_arena *a, const char *file, int line)
-#else
 gc_malloc(size_t size, bool clear, struct gc_arena *a)
-#endif
 {
     void *ret;
     if (a)
     {
         struct gc_entry *e;
-#ifdef DMALLOC
-        e = (struct gc_entry *)openvpn_dmalloc(file, line, size + sizeof(struct gc_entry));
-#else
         e = (struct gc_entry *)malloc(size + sizeof(struct gc_entry));
-#endif
         check_malloc_return(e);
         ret = (char *)e + sizeof(struct gc_entry);
         e->next = a->list;
@@ -357,11 +329,7 @@ gc_malloc(size_t size, bool clear, struct gc_arena *a)
     }
     else
     {
-#ifdef DMALLOC
-        ret = openvpn_dmalloc(file, line, size);
-#else
         ret = malloc(size);
-#endif
         check_malloc_return(ret);
     }
 #ifndef ZERO_BUFFER_ON_ALLOC
@@ -444,11 +412,7 @@ gc_addspecial(void *addr, void (*free_function)(void *), struct gc_arena *a)
 {
     ASSERT(a);
     struct gc_entry_special *e;
-#ifdef DMALLOC
-    e = (struct gc_entry_special *)openvpn_dmalloc(file, line, sizeof(struct gc_entry_special));
-#else
     e = (struct gc_entry_special *)malloc(sizeof(struct gc_entry_special));
-#endif
     check_malloc_return(e);
     e->free_fnc = free_function;
     e->addr = addr;
@@ -649,11 +613,7 @@ rm_trailing_chars(char *str, const char *what_to_delete)
  * Allocate a string
  */
 char *
-#ifdef DMALLOC
-string_alloc_debug(const char *str, struct gc_arena *gc, const char *file, int line)
-#else
 string_alloc(const char *str, struct gc_arena *gc)
-#endif
 {
     if (str)
     {
@@ -662,11 +622,7 @@ string_alloc(const char *str, struct gc_arena *gc)
 
         if (gc)
         {
-#ifdef DMALLOC
-            ret = (char *)gc_malloc_debug(n, false, gc, file, line);
-#else
             ret = (char *)gc_malloc(n, false, gc);
-#endif
         }
         else
         {
@@ -674,11 +630,7 @@ string_alloc(const char *str, struct gc_arena *gc)
              * that the caller cleans up afterwards.  This is coherent with the
              * earlier behaviour when gc_malloc() would be called with gc == NULL
              */
-#ifdef DMALLOC
-            ret = openvpn_dmalloc(file, line, n);
-#else
             ret = calloc(1, n);
-#endif
             check_malloc_return(ret);
         }
         memcpy(ret, str, n);
@@ -752,21 +704,13 @@ print_argv(const char **p, struct gc_arena *gc, const unsigned int flags)
  * Allocate a string inside a buffer
  */
 struct buffer
-#ifdef DMALLOC
-string_alloc_buf_debug(const char *str, struct gc_arena *gc, const char *file, int line)
-#else
 string_alloc_buf(const char *str, struct gc_arena *gc)
-#endif
 {
     struct buffer buf;
 
     ASSERT(str);
 
-#ifdef DMALLOC
-    buf_set_read(&buf, (uint8_t *)string_alloc_debug(str, gc, file, line), strlen(str) + 1);
-#else
     buf_set_read(&buf, (uint8_t *)string_alloc(str, gc), strlen(str) + 1);
-#endif
 
     if (buf.len > 0) /* Don't count trailing '\0' as part of length */
     {
index 797bd08616de6ec2eb2103bf102c01e1c26682c7..743c3f42f359428716a69e90c636bd53431ae41c 100644 (file)
@@ -147,32 +147,6 @@ char *print_argv(const char **p, struct gc_arena *gc, const unsigned int flags);
 
 void buf_size_error(const size_t size);
 
-/* for dmalloc debugging */
-
-#ifdef DMALLOC
-
-#define alloc_buf(size)               alloc_buf_debug(size, __FILE__, __LINE__)
-#define alloc_buf_gc(size, gc)        alloc_buf_gc_debug(size, gc, __FILE__, __LINE__);
-#define clone_buf(buf)                clone_buf_debug(buf, __FILE__, __LINE__);
-#define gc_malloc(size, clear, arena) gc_malloc_debug(size, clear, arena, __FILE__, __LINE__)
-#define string_alloc(str, gc)         string_alloc_debug(str, gc, __FILE__, __LINE__)
-#define string_alloc_buf(str, gc)     string_alloc_buf_debug(str, gc, __FILE__, __LINE__)
-
-struct buffer alloc_buf_debug(size_t size, const char *file, int line);
-
-struct buffer alloc_buf_gc_debug(size_t size, struct gc_arena *gc, const char *file, int line);
-
-struct buffer clone_buf_debug(const struct buffer *buf, const char *file, int line);
-
-void *gc_malloc_debug(size_t size, bool clear, struct gc_arena *a, const char *file, int line);
-
-char *string_alloc_debug(const char *str, struct gc_arena *gc, const char *file, int line);
-
-struct buffer string_alloc_buf_debug(const char *str, struct gc_arena *gc, const char *file,
-                                     int line);
-
-#else  /* ifdef DMALLOC */
-
 struct buffer alloc_buf(size_t size);
 
 struct buffer alloc_buf_gc(size_t size,
@@ -186,8 +160,6 @@ char *string_alloc(const char *str, struct gc_arena *gc);
 
 struct buffer string_alloc_buf(const char *str, struct gc_arena *gc);
 
-#endif /* ifdef DMALLOC */
-
 void gc_addspecial(void *addr, void (*free_function)(void *), struct gc_arena *a);
 
 /**
index b602ba1cacb12133c844a8da02b7c10c4052315d..17085d6124f0a45510a0af9287a4829685423726 100644 (file)
@@ -102,16 +102,6 @@ provider_t *crypto_load_provider(const char *provider);
  */
 void crypto_unload_provider(const char *provname, provider_t *provider);
 
-#ifdef DMALLOC
-/*
- * OpenSSL memory debugging.  If dmalloc debugging is enabled, tell
- * OpenSSL to use our private malloc/realloc/free functions so that
- * we can dispatch them to dmalloc.
- */
-void crypto_init_dmalloc(void);
-
-#endif /* DMALLOC */
-
 void show_available_ciphers(void);
 
 void show_available_digests(void);
index debd53d83c83591ea0c4de1744afa3a0e0897932..9e47c2686e0cf5ed92df3cf681e97c7cc79db8eb 100644 (file)
@@ -139,14 +139,6 @@ mbed_log_func_line(unsigned int flags, int errval, const char *func, int line)
 }
 
 
-#ifdef DMALLOC
-void
-crypto_init_dmalloc(void)
-{
-    msg(M_ERR, "Error: dmalloc support is not available for mbed TLS.");
-}
-#endif /* DMALLOC */
-
 const cipher_name_pair cipher_name_translation_table[] = {
     { "BF-CBC", "BLOWFISH-CBC" },
     { "BF-CFB", "BLOWFISH-CFB64" },
index fa9eb6702595aadb31a60c41391ac7442284dfbe..1191f20b540d2088a98c76fa40b043fde2aceadb 100644 (file)
@@ -39,6 +39,7 @@
 #include "integer.h"
 #include "crypto.h"
 #include "crypto_backend.h"
+#include "memdbg.h"
 #include "openssl_compat.h"
 
 #include <openssl/conf.h>
@@ -273,40 +274,6 @@ crypto_print_openssl_errors(const unsigned int flags)
 }
 
 
-/*
- *
- * OpenSSL memory debugging.  If dmalloc debugging is enabled, tell
- * OpenSSL to use our private malloc/realloc/free functions so that
- * we can dispatch them to dmalloc.
- *
- */
-
-#ifdef DMALLOC
-static void *
-crypto_malloc(size_t size, const char *file, int line)
-{
-    return dmalloc_malloc(file, line, size, DMALLOC_FUNC_MALLOC, 0, 0);
-}
-
-static void *
-crypto_realloc(void *ptr, size_t size, const char *file, int line)
-{
-    return dmalloc_realloc(file, line, ptr, size, DMALLOC_FUNC_REALLOC, 0);
-}
-
-static void
-crypto_free(void *ptr)
-{
-    dmalloc_free(__FILE__, __LINE__, ptr, DMALLOC_FUNC_FREE);
-}
-
-void
-crypto_init_dmalloc(void)
-{
-    CRYPTO_set_mem_ex_functions(crypto_malloc, crypto_realloc, crypto_free);
-}
-#endif /* DMALLOC */
-
 const cipher_name_pair cipher_name_translation_table[] = {
     { "AES-128-GCM", "id-aes128-GCM" },
     { "AES-192-GCM", "id-aes192-GCM" },
index 906a83ca7eaf1b0a33c049fd862bc76b87b0d24e..69d226d3e8a2d08b5450785f0ada803cdeb28cdd 100644 (file)
@@ -838,11 +838,6 @@ init_port_share(struct context *c)
 bool
 init_static(void)
 {
-#if defined(DMALLOC)
-    crypto_init_dmalloc();
-#endif
-
-
     /*
      * Initialize random number seed.  random() is only used
      * when "weak" random numbers are acceptable.
index ea620c23d0482c84f366c42370ebcd0e74906a28..1f945825e965050645a8c567636ba883725e5936 100644 (file)
  */
 
 #ifdef USE_VALGRIND
-
 #include <valgrind/memcheck.h>
-
-#define VALGRIND_MAKE_READABLE(addr, len)
-
-#else /* ifdef USE_VALGRIND */
-
-#define VALGRIND_MAKE_READABLE(addr, len)
-
-#endif
-
-#ifdef DMALLOC /* see ./configure options to enable */
-
-/*
- * See ./configure options to enable dmalloc
- * support for memory leak checking.
- *
- * The dmalloc package can be downloaded from:
- *
- *     https://dmalloc.com/
- *
- * When dmalloc is installed and enabled,
- * use this command prior to running openvpn:
- *
- *    dmalloc -l dlog -i 100 low -p log-unknown
- *
- * Also, put this in your .bashrc file:
- *
- *    function dmalloc { eval `command dmalloc -b $*`; }
- *
- * Or take a more low-level approach:
- *
- *    export DMALLOC_OPTIONS="debug=0x4e48503,inter=100,log=dlog"
- *
- *  NOTE: When building dmalloc you need to add something
- *  like this to dmalloc's settings.h -- it will allocate a static
- *  buffer to be used as the malloc arena:
- *
- *  #define INTERNAL_MEMORY_SPACE (1024 * 1024 * 50)
- */
-
-#include <dmalloc.h>
-
-#define openvpn_dmalloc(file, line, size) \
-    dmalloc_malloc((file), (line), (size), DMALLOC_FUNC_MALLOC, 0, 0)
-
-/*
- * This #define will put the line number of the log
- * file position where leaked memory was allocated instead
- * of the source code file and line number.  Make sure
- * to increase the size of dmalloc's info tables,
- * (MEMORY_TABLE_SIZE in settings.h)
- * otherwise it might get overwhelmed by the large
- * number of unique file/line combinations.
- */
-#if 0
-#undef malloc
-#define malloc(size) openvpn_dmalloc("logfile", x_msg_line_num, (size))
 #endif
 
-#endif /* DMALLOC */
+#define VALGRIND_MAKE_READABLE(addr, len)
 
 /*
  * Force buffers to be zeroed after allocation.