From 4c6fd94de34c2949a89271350f963ce0b12375e1 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 7 Jun 2014 22:29:28 +0100 Subject: [PATCH] src/query.c: New function `adns__free_interim' for releasing memory. Useful, for example, if you're growing a dynamically allocated array. Signed-off-by: Mark Wooding --- src/internal.h | 4 ++++ src/query.c | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/internal.h b/src/internal.h index 7faa212..a537115 100644 --- a/src/internal.h +++ b/src/internal.h @@ -672,6 +672,10 @@ void adns__transfer_interim(adns_query from, adns_query to, void *block); * TTLs get inherited by their parents. */ +void adns__free_interim(adns_query qu, void *p); +/* Forget about a block allocated by adns__alloc_interim. + */ + void *adns__alloc_mine(adns_query qu, size_t sz); /* Like _interim, but does not record the length for later * copying into the answer. This just ensures that the memory diff --git a/src/query.c b/src/query.c index c18ba8e..ebbfd53 100644 --- a/src/query.c +++ b/src/query.c @@ -415,6 +415,17 @@ static allocnode *alloc_info(adns_query qu, void *p, size_t *sz_r) { return an; } +void adns__free_interim(adns_query qu, void *p) { + size_t sz; + allocnode *an= alloc_info(qu, p, &sz); + + if (!an) return; + assert(!qu->final_allocspace); + LIST_UNLINK(qu->allocations, an); + free(an); + qu->interim_allocd -= sz; +} + void *adns__alloc_mine(adns_query qu, size_t sz) { return alloc_common(qu,MEM_ROUND(sz)); } -- 2.30.2