summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMark Wooding <mdw@distorted.org.uk>2014-06-07 22:29:28 +0100
committerIan Jackson <ijackson@chiark.greenend.org.uk>2014-10-19 21:09:55 +0100
commit4c6fd94de34c2949a89271350f963ce0b12375e1 (patch)
tree27a635cb9b8d0b233c5d8f6e93bc2afee082d0a6 /src
parent2edb1757691323cf8a54d6acd68251781a4df521 (diff)
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 <mdw@distorted.org.uk>
Diffstat (limited to 'src')
-rw-r--r--src/internal.h4
-rw-r--r--src/query.c11
2 files changed, 15 insertions, 0 deletions
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));
}