From 3f2bfca3df1ac0d096e12a46acbd3115dfec6348 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Fri, 13 Feb 2026 12:54:54 +0000 Subject: [PATCH] Log memory allocated by libidn when --log-malloc active. --- src/dnsmasq.h | 2 ++ src/util.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/dnsmasq.h b/src/dnsmasq.h index 1c001a8..42cc4a7 100644 --- a/src/dnsmasq.h +++ b/src/dnsmasq.h @@ -1497,11 +1497,13 @@ unsigned char *do_rfc1035_name(unsigned char *p, char *sval, char *limit); void *safe_malloc(size_t size); void safe_strncpy(char *dest, const char *src, size_t size); void safe_pipe(int *fd, int read_noblock); +#define malloc_log(x, y) malloc_log_real(__func__, __LINE__, (x), (y)) #define whine_malloc(x) whine_malloc_real(__func__, __LINE__, (x)) #define whine_realloc(x, y) whine_realloc_real(NULL, __func__, __LINE__, (x), (y)) #define expand_buf(x, y) expand_buf_real(__func__, __LINE__, (x), (y)) #define expand_workspace(x, y, z) expand_workspace_real(__func__, __LINE__, (x), (y), (z)) #define free(x) free_real(__func__, __LINE__, (x)) +void malloc_log_real(const char *func, unsigned int line, void *mem, size_t size); void free_real(const char *func, unsigned int line, void *ptr); void *whine_malloc_real(const char *func, unsigned int line, size_t size); void *whine_realloc_real(const char *wrapper, const char *func, unsigned int line, void *ptr, size_t size); diff --git a/src/util.c b/src/util.c index ff642ba..44eada2 100644 --- a/src/util.c +++ b/src/util.c @@ -266,6 +266,10 @@ char *canonicalise(char *in, int *nomem) return NULL; } + + /* IDN library doesnt call our malloc wrapper, so log this by steam */ + if (ret) + malloc_log(ret, strlen(ret)+1); return ret; } @@ -993,6 +997,12 @@ int expand_workspace_real(const char *func, unsigned int line, unsigned char *** return 1; } +void malloc_log_real(const char *func, unsigned int line, void *mem, size_t size) +{ + if (mem && daemon->log_malloc) + my_syslog(LOG_INFO, _("malloc: %s:%u %zu bytes at %x"), func, line, size, hash_ptr(mem)); +} + #undef free void free_real(const char *func, unsigned int line, void *ptr) {