Author: rhuijben
Date: Wed Nov  4 18:04:31 2015
New Revision: 1712602

URL: http://svn.apache.org/viewvc?rev=1712602&view=rev
Log:
Add some debug only code to the hpack table to explicitly release memory
from pool cleanup (which the next cleanup handler already handles, but
which may trigger leak warnings while debugging)

* buckets/hpack_buckets.c
  (cleanup_hpack_table): New function.
  (serf__hpack_table_create): Register cleanup_hpack_tbl.

Modified:
    serf/trunk/buckets/hpack_buckets.c

Modified: serf/trunk/buckets/hpack_buckets.c
URL: 
http://svn.apache.org/viewvc/serf/trunk/buckets/hpack_buckets.c?rev=1712602&r1=1712601&r2=1712602&view=diff
==============================================================================
--- serf/trunk/buckets/hpack_buckets.c (original)
+++ serf/trunk/buckets/hpack_buckets.c Wed Nov  4 18:04:31 2015
@@ -376,6 +376,37 @@ static const serf_hpack_entry_t hpack_st
 static const apr_uint64_t hpack_static_table_count =
       (sizeof(hpack_static_table) / sizeof(hpack_static_table[0]));
 
+static apr_status_t
+cleanup_hpack_table(void *data)
+{
+#ifdef _DEBUG
+  serf_hpack_table_t *tbl = data;
+  serf_hpack_entry_t *hi, *next;
+
+  /* This is not really necessary, as we create our own allocator,
+     which lives in the same pool. But it helps tracking down
+     memory leaks in different locations */
+  for (hi = tbl->lr_first; hi; hi = next)
+    {
+      next = hi->next;
+
+      hpack_free_entry(hi, tbl->alloc);
+    }
+  tbl->lr_first = tbl->lr_start = tbl->lr_last = NULL;
+  tbl->lr_size = 0;
+
+  for (hi = tbl->rl_first; hi; hi = next)
+    {
+      next = hi->next;
+
+      hpack_free_entry(hi, tbl->alloc);
+    }
+  tbl->rl_first = tbl->rl_start = tbl->rl_last = NULL;
+  tbl->rl_size = 0;
+#endif
+  return APR_SUCCESS;
+}
+
 
 serf_hpack_table_t *
 serf__hpack_table_create(int for_http2,
@@ -387,6 +418,11 @@ serf__hpack_table_create(int for_http2,
   tbl->pool = result_pool;
   tbl->alloc = serf_bucket_allocator_create(result_pool, NULL, NULL);
 
+  /* We register this this after creating the allocator, or we would touch
+     memory that is already freed.*/
+  apr_pool_cleanup_register(result_pool, tbl, cleanup_hpack_table,
+                            apr_pool_cleanup_null);
+
   tbl->lr_sys_table_size = tbl->lr_max_table_size = default_max_table_size;
   tbl->rl_sys_table_size = tbl->rl_max_table_size = default_max_table_size;
 


Reply via email to