diff --git a/src/dnsmasq.h b/src/dnsmasq.h index d93ad16..1c001a8 100644 --- a/src/dnsmasq.h +++ b/src/dnsmasq.h @@ -1498,11 +1498,15 @@ 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 whine_malloc(x) whine_malloc_real(__func__, __LINE__, (x)) -#define whine_realloc(x, y) whine_realloc_real(__func__, __LINE__, (x), (y)) +#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 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 *func, unsigned int line, void *ptr, size_t size); +void *whine_realloc_real(const char *wrapper, const char *func, unsigned int line, void *ptr, size_t size); +int expand_buf_real(const char *func, unsigned int line, struct iovec *iov, size_t size); +int expand_workspace_real(const char *func, unsigned int line, unsigned char ***wkspc, int *szp, int new); int sa_len(union mysockaddr *addr); int sockaddr_isequal(const union mysockaddr *s1, const union mysockaddr *s2); int sockaddr_isnull(const union mysockaddr *s); @@ -1524,7 +1528,6 @@ int parse_hex(char *in, unsigned char *out, int maxlen, unsigned int *wildcard_mask, int *mac_type); int memcmp_masked(unsigned char *a, unsigned char *b, int len, unsigned int mask); -int expand_buf(struct iovec *iov, size_t size); char *print_mac(char *buff, unsigned char *mac, int len); int read_write(int fd, unsigned char *packet, int size, int rw); int read_writev(int fd, struct iovec *iov, int iovcnt, int rw); @@ -1916,7 +1919,6 @@ int do_poll(int timeout); /* rrfilter.c */ size_t rrfilter(struct dns_header *header, size_t *plen, int mode); short *rrfilter_desc(int type); -int expand_workspace(unsigned char ***wkspc, int *szp, int new); int to_wire(char *name); void from_wire(char *name); /* modes. */ diff --git a/src/rrfilter.c b/src/rrfilter.c index d13ed22..29f69c7 100644 --- a/src/rrfilter.c +++ b/src/rrfilter.c @@ -337,27 +337,6 @@ short *rrfilter_desc(int type) return p+1; } -int expand_workspace(unsigned char ***wkspc, int *szp, int new) -{ - unsigned char **p; - int old = *szp; - - if (old >= new+1) - return 1; - - new += 5; - - if (!(p = whine_realloc(*wkspc, new * sizeof(unsigned char *)))) - return 0; - - memset(p+old, 0, new-old); - - *wkspc = p; - *szp = new; - - return 1; -} - /* Convert from presentation format to wire format, in place. Also map UC -> LC. Note that using extract_name to get presentation format diff --git a/src/util.c b/src/util.c index aed2567..ff642ba 100644 --- a/src/util.c +++ b/src/util.c @@ -672,26 +672,6 @@ int memcmp_masked(unsigned char *a, unsigned char *b, int len, unsigned int mask return count; } -/* _note_ may copy buffer */ -int expand_buf(struct iovec *iov, size_t size) -{ - void *new; - - if (size <= (size_t)iov->iov_len) - return 1; - - if (!(new = whine_realloc(iov->iov_base, size))) - { - errno = ENOMEM; - return 0; - } - - iov->iov_base = new; - iov->iov_len = size; - - return 1; -} - char *print_mac(char *buff, unsigned char *mac, int len) { char *p = buff; @@ -955,7 +935,7 @@ void *whine_malloc_real(const char *func, unsigned int line, size_t size) return ret; } -void *whine_realloc_real(const char *func, unsigned int line, void *ptr, size_t size) +void *whine_realloc_real(const char *wrapper, const char *func, unsigned int line, void *ptr, size_t size) { unsigned int old = hash_ptr(ptr); void *ret = realloc(ptr, size); @@ -963,11 +943,56 @@ void *whine_realloc_real(const char *func, unsigned int line, void *ptr, size_t if (!ret) my_syslog(LOG_ERR, _("failed to reallocate %d bytes"), (int) size); else if (daemon->log_malloc) - my_syslog(LOG_INFO, _("realloc: %s:%u %zu bytes from %x to %x"), func, line, size, old, hash_ptr(ret)); + { + if (!wrapper) + wrapper = "realloc"; + my_syslog(LOG_INFO, _("%s: %s:%u %zu bytes from %x to %x"), wrapper, func, line, size, old, hash_ptr(ret)); + } return ret; } +/* _note_ may copy buffer */ +int expand_buf_real(const char *func, unsigned int line, struct iovec *iov, size_t size) +{ + void *new; + + if (size <= (size_t)iov->iov_len) + return 1; + + if (!(new = whine_realloc_real("expand_buf", func, line, iov->iov_base, size))) + { + errno = ENOMEM; + return 0; + } + + iov->iov_base = new; + iov->iov_len = size; + + return 1; +} + +int expand_workspace_real(const char *func, unsigned int line, unsigned char ***wkspc, int *szp, int new) +{ + unsigned char **p; + int old = *szp; + + if (old >= new+1) + return 1; + + new += 5; + + if (!(p = whine_realloc_real("expand_workspace", func, line, *wkspc, new * sizeof(unsigned char *)))) + return 0; + + memset(p+old, 0, new-old); + + *wkspc = p; + *szp = new; + + return 1; +} + #undef free void free_real(const char *func, unsigned int line, void *ptr) {