Skip to contentSkip to conversation

Change in openvpn[master]: Fix compilation with --with-mem-check=dmalloc

Openvpn-devel flichtenheld (Code Review) 1 participant 1 message Mar 18 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1773842036000.I4920318ac537064508eee3ca449d48de76c2ea5d@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1582?usp=email

to review the following change.

Change subject: Fix compilation with --with-mem-check=dmalloc
......................................................................

Fix compilation with --with-mem-check=dmalloc

Only tested compilation and make check. Did not
actually verify dmalloc functionality.

Change-Id I4920318ac537064508eee3ca449d48de76c2ea5d

---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/crypto_openssl.c

3 files changed, 21 insertions(+), 12 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/82/1582/1

src/openvpn/buffer.c +5 -1
index 75110ed..e335eb0 100644
@@ -440,7 +440,11 @@
 }
 
 void
+#ifdef DMALLOC
+gc_addspecial_debug(void *addr, void (*free_function)(void *), struct gc_arena *a, const char *file, int line)
+#else
 gc_addspecial(void *addr, void (*free_function)(void *), struct gc_arena *a)
+#endif
 {
     ASSERT(a);
     struct gc_entry_special *e;
@@ -1157,7 +1161,7 @@
     if (buf && buf->len)
     {
         msglvl_t msglevel = D_ALIGN_DEBUG;
-        const unsigned int u = (unsigned int)BPTR(buf);
+        const uintptr_t u = (uintptr_t)BPTR(buf);
 
         if (u & (PAYLOAD_ALIGN - 1))
         {
src/openvpn/buffer.h +12 -8
index 87d7d80..fbabfb3 100644
@@ -243,12 +243,13 @@
 
 #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__)
+#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 gc_addspecial(addr, func, arena) gc_addspecial_debug(addr, func, 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__)
 
 /** Debug variant of \c alloc_buf() that records the allocation site. */
 struct buffer alloc_buf_debug(size_t size, const char *file, int line);
@@ -262,6 +263,9 @@
 /** Debug variant of \c gc_malloc() that records the allocation site. */
 void *gc_malloc_debug(size_t size, bool clear, struct gc_arena *a, const char *file, int line);
 
+/** Debug variant of \c gc_addspecial() that records the allocation site. */
+void gc_addspecial_debug(void *addr, void (*free_function)(void *), struct gc_arena *a, const char *file, int line);
+
 /** Debug variant of \c string_alloc() that records the allocation site. */
 char *string_alloc_debug(const char *str, struct gc_arena *gc, const char *file, int line);
 
@@ -351,8 +355,6 @@
  */
 struct buffer string_alloc_buf(const char *str, struct gc_arena *gc);
 
-#endif /* ifdef DMALLOC */
-
 /**
  * Register an address with a custom free function in a garbage collection
  * arena.
@@ -367,6 +369,8 @@
  */
 void gc_addspecial(void *addr, void (*free_function)(void *), struct gc_arena *a);
 
+#endif /* ifdef DMALLOC */
+
 /**
  * allows to realloc a pointer previously allocated by gc_malloc or gc_realloc
  *
src/openvpn/crypto_openssl.c +4 -3
index 19cb9a9..b526b0b 100644
@@ -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>
@@ -295,15 +296,15 @@
 }
 
 static void
-crypto_free(void *ptr)
+crypto_free(void *ptr, const char *file, int line)
 {
-    dmalloc_free(__FILE__, __LINE__, ptr, DMALLOC_FUNC_FREE);
+    dmalloc_free(file, line, ptr, DMALLOC_FUNC_FREE);
 }
 
 void
 crypto_init_dmalloc(void)
 {
-    CRYPTO_set_mem_ex_functions(crypto_malloc, crypto_realloc, crypto_free);
+    CRYPTO_set_mem_functions(crypto_malloc, crypto_realloc, crypto_free);
 }
 #endif /* DMALLOC */
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1582?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4920318ac537064508eee3ca449d48de76c2ea5d
Gerrit-Change-Number: 1582
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>