From: Mark Wooding Date: Sat, 7 Jun 2014 21:29:28 +0000 (+0100) Subject: src/query.c: New function `adns__free_interim' for releasing memory. X-Git-Tag: adns-1.5.0-rc0~74 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=adns.git;a=commitdiff_plain;h=4c6fd94de34c2949a89271350f963ce0b12375e1;hp=2edb1757691323cf8a54d6acd68251781a4df521 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 --- 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)); }