chiark / gitweb /
src/query.c: New function `adns__free_interim' for releasing memory.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 7 Jun 2014 21:29:28 +0000 (22:29 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 19 Oct 2014 20:09:55 +0000 (21:09 +0100)
Useful, for example, if you're growing a dynamically allocated array.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
src/internal.h
src/query.c

index 7faa2123c4abe4bffec95183ed607c0ed1551536..a53711535246c13678872b0799a6d254ffb27bc0 100644 (file)
@@ -672,6 +672,10 @@ void adns__transfer_interim(adns_query from, adns_query to, void *block);
  * TTLs get inherited by their parents.
  */
 
  * 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
 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
index c18ba8e991c3481f33057bf44145a6025a2d3605..ebbfd53a135416ea7b6575121b846a67d8c8f6ab 100644 (file)
@@ -415,6 +415,17 @@ static allocnode *alloc_info(adns_query qu, void *p, size_t *sz_r) {
   return an;
 }
 
   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));
 }
 void *adns__alloc_mine(adns_query qu, size_t sz) {
   return alloc_common(qu,MEM_ROUND(sz));
 }