From 98b1ff624a3bedc375f4597dcf7e426b7fa461c8 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Fri, 11 May 2018 11:23:19 +0200 Subject: [PATCH] Memory loss with empty string bindata's --- src/context.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/context.c b/src/context.c index ae974a5b..4b5a77ad 100644 --- a/src/context.c +++ b/src/context.c @@ -3787,13 +3787,14 @@ _getdns_strdup(const struct mem_funcs *mfs, const char *s) return memcpy(r, s, sz); } +static uint8_t _getdns_bindata_nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + struct getdns_bindata * _getdns_bindata_copy(struct mem_funcs *mfs, size_t size, const uint8_t *data) { /* Don't know why, but nodata allows * empty bindatas with the python bindings */ - static uint8_t nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; struct getdns_bindata *dst; if (!(dst = GETDNS_MALLOC(*mfs, struct getdns_bindata))) @@ -3807,7 +3808,7 @@ _getdns_bindata_copy(struct mem_funcs *mfs, size_t size, const uint8_t *data) } (void) memcpy(dst->data, data, size); } else { - dst->data = nodata; + dst->data = _getdns_bindata_nodata; } return dst; } @@ -3819,7 +3820,8 @@ _getdns_bindata_destroy(struct mem_funcs *mfs, if (!bindata) return; - if (bindata->size) GETDNS_FREE(*mfs, bindata->data); + if (bindata->data && bindata->data != _getdns_bindata_nodata) + GETDNS_FREE(*mfs, bindata->data); GETDNS_FREE(*mfs, bindata); }