]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix that alloc stats has strdup checks, it stops debuggers from
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Fri, 2 Aug 2024 06:54:54 +0000 (08:54 +0200)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Fri, 2 Aug 2024 06:54:54 +0000 (08:54 +0200)
  complaining about mismatch at free time.

config.h.in
configure.ac
doc/Changelog
util/alloc.c

index 4a7143c52527064832c3fd2b34831c235962543d..099206025a33af44b7ee46b3bc146574777c7399 100644 (file)
@@ -1496,6 +1496,7 @@ struct sockaddr_storage;
 #  define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__)
 #  define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
 #  define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
+#  define strdup(s) unbound_stat_strdup_log(s, __FILE__, __LINE__, __func__)
 void *unbound_stat_malloc(size_t size);
 void *unbound_stat_calloc(size_t nmemb, size_t size);
 void unbound_stat_free(void *ptr);
@@ -1508,6 +1509,8 @@ void unbound_stat_free_log(void *ptr, const char* file, int line,
        const char* func);
 void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
        int line, const char* func);
+char *unbound_stat_strdup_log(const char *s, const char* file, int line,
+       const char* func);
 #elif defined(UNBOUND_ALLOC_LITE)
 #  include "util/alloc.h"
 #endif /* UNBOUND_ALLOC_LITE and UNBOUND_ALLOC_STATS */
index 4d17fb8c192785102d20600b061b18de8860d441..feeaf34c29aa1a9807ea32f39512c52138ca8b20 100644 (file)
@@ -2329,6 +2329,7 @@ struct sockaddr_storage;
 #  define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__)
 #  define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
 #  define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
+#  define strdup(s) unbound_stat_strdup_log(s, __FILE__, __LINE__, __func__)
 void *unbound_stat_malloc(size_t size);
 void *unbound_stat_calloc(size_t nmemb, size_t size);
 void unbound_stat_free(void *ptr);
@@ -2341,6 +2342,8 @@ void unbound_stat_free_log(void *ptr, const char* file, int line,
        const char* func);
 void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
        int line, const char* func);
+char *unbound_stat_strdup_log(const char *s, const char* file, int line,
+       const char* func);
 #elif defined(UNBOUND_ALLOC_LITE)
 #  include "util/alloc.h"
 #endif /* UNBOUND_ALLOC_LITE and UNBOUND_ALLOC_STATS */
index f94ed7fec6e26b2dc12dfaaf25fda2b1d072b6df..a3c4bda0939057666b3eac954352e2222d2d063c 100644 (file)
@@ -1,3 +1,7 @@
+2 August 2024: Wouter
+       - Fix that alloc stats has strdup checks, it stops debuggers from
+         complaining about mismatch at free time.
+
 1 August 2024: Wouter
        - Fix dnstap test program, cleans up to have clean memory on exit,
          for tap_data_free, does not delete NULL items. Also it does not try
index 7e9618931ca6ab8a6ed58319f7f9c3bb7aea8c3e..d00976b7fa5eb23bf1cae69fdf4531413d522252 100644 (file)
@@ -466,6 +466,19 @@ void *unbound_stat_realloc(void *ptr, size_t size)
        memcpy(res+8, &mem_special, sizeof(mem_special));
        return res+16;
 }
+/** strdup with stats */
+char *unbound_stat_strdup(const char* s)
+{
+       size_t len;
+       char* res;
+       if(!s) return NULL;
+       len = strlen(s);
+       res = unbound_stat_malloc(len+1);
+       if(!res) return NULL;
+       memmove(res, s, len);
+       res[len]=0;
+       return res;
+}
 
 /** log to file where alloc was done */
 void *unbound_stat_malloc_log(size_t size, const char* file, int line,
@@ -507,6 +520,15 @@ void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
        return unbound_stat_realloc(ptr, size);
 }
 
+/** log to file where strdup was done */
+char *unbound_stat_strdup_log(const char *s, const char* file, int line,
+       const char* func)
+{
+       log_info("%s:%d %s strdup size %u", file, line, func,
+               (s?(unsigned)strlen(s)+1:0));
+       return unbound_stat_strdup(s);
+}
+
 #endif /* UNBOUND_ALLOC_STATS */
 #ifdef UNBOUND_ALLOC_LITE
 #undef malloc