On 2016-11-14 22:43:16 [+0100], gregor herrmann wrote:
> Yay, this looks good!

So upstream came up with the patch attached after I forwaded mine. Can
you please confirm whether this works or not?

> Cheers,
> gregor

Sebastian
diff --git a/src/prototypes.h b/src/prototypes.h
index c196f92..86f4631 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -776,6 +776,7 @@ void *str_alloc_debug(size_t, const char *, int);
 #define str_alloc(a) str_alloc_debug((a), __FILE__, __LINE__)
 void *str_alloc_detached_debug(size_t, const char *, int);
 #define str_alloc_detached(a) str_alloc_detached_debug((a), __FILE__, __LINE__)
+void *str_realloc_detached_debug(void *, size_t, const char *, int);
 void *str_realloc_debug(void *, size_t, const char *, int);
 #define str_realloc(a, b) str_realloc_debug((a), (b), __FILE__, __LINE__)
 void str_detach_debug(void *, const char *, int);
diff --git a/src/str.c b/src/str.c
index 524015a..b4331f7 100644
--- a/src/str.c
+++ b/src/str.c
@@ -90,6 +90,8 @@ NOEXPORT int leak_result_num=0;
 NOEXPORT LPTSTR str_vtprintf(LPCTSTR, va_list);
 #endif /* USE_WIN32 */
 
+NOEXPORT void *str_realloc_internal_debug(void *, size_t, const char *, int);
+
 NOEXPORT ALLOC_LIST *get_alloc_list_ptr(void *, const char *, int);
 NOEXPORT void str_leak_debug(const ALLOC_LIST *, int);
 
@@ -288,10 +290,22 @@ void *str_alloc_detached_debug(size_t size, const char *file, int line) {
 }
 
 void *str_realloc_debug(void *ptr, size_t size, const char *file, int line) {
+    if(ptr)
+        return str_realloc_internal_debug(ptr, size, file, line);
+    else
+        return str_alloc_debug(size, file, line);
+}
+
+void *str_realloc_detached_debug(void *ptr, size_t size, const char *file, int line) {
+    if(ptr)
+        return str_realloc_internal_debug(ptr, size, file, line);
+    else
+        return str_alloc_detached_debug(size, file, line);
+}
+
+NOEXPORT void *str_realloc_internal_debug(void *ptr, size_t size, const char *file, int line) {
     ALLOC_LIST *prev_alloc_list, *alloc_list;
 
-    if(!ptr)
-        return str_alloc_debug(size, file, line);
     prev_alloc_list=get_alloc_list_ptr(ptr, file, line);
     str_leak_debug(prev_alloc_list, -1);
     if(prev_alloc_list->size>size) /* shrinking the allocation */
diff --git a/src/tls.c b/src/tls.c
index 3964f9c..624022f 100644
--- a/src/tls.c
+++ b/src/tls.c
@@ -54,10 +54,10 @@ void tls_init() {
     ui_tls=tls_alloc(NULL, NULL, "ui");
 #if OPENSSL_VERSION_NUMBER>=0x10100000L
     CRYPTO_set_mem_functions(str_alloc_detached_debug,
-        str_realloc_debug, str_free_debug);
+        str_realloc_detached_debug, str_free_debug);
 #else
     CRYPTO_set_mem_ex_functions(str_alloc_detached_debug,
-        str_realloc_debug, free_function);
+        str_realloc_detached_debug, free_function);
 #endif
 }
 

Reply via email to