From 5a8a8073b8efbf6c18ff4a161cc8f1e4f291556c Mon Sep 17 00:00:00 2001
From: Craig Tiller <ctiller@google.com>
Date: Fri, 30 Jan 2015 09:41:25 -0800
Subject: [PATCH] Free some leaks in http_server_filter

---
 src/core/channel/http_server_filter.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/core/channel/http_server_filter.c b/src/core/channel/http_server_filter.c
index 2658a6d42e..3e5bb0506a 100644
--- a/src/core/channel/http_server_filter.c
+++ b/src/core/channel/http_server_filter.c
@@ -319,8 +319,8 @@ static void init_channel_elem(grpc_channel_element *elem,
       if (channeld->gettable_count == gettable_capacity) {
         gettable_capacity =
             GPR_MAX(gettable_capacity * 3 / 2, gettable_capacity + 1);
-        channeld->gettables =
-            gpr_realloc(channeld->gettables, gettable_capacity * sizeof(gettable));
+        channeld->gettables = gpr_realloc(channeld->gettables,
+                                          gettable_capacity * sizeof(gettable));
       }
       g = &channeld->gettables[channeld->gettable_count++];
       g->path = grpc_mdelem_from_strings(mdctx, ":path", p->path);
@@ -334,9 +334,17 @@ static void init_channel_elem(grpc_channel_element *elem,
 
 /* Destructor for channel data */
 static void destroy_channel_elem(grpc_channel_element *elem) {
+  size_t i;
+
   /* grab pointers to our data from the channel element */
   channel_data *channeld = elem->channel_data;
 
+  for (i = 0; i < channeld->gettable_count; i++) {
+    grpc_mdelem_unref(channeld->gettables[i].path);
+    grpc_mdelem_unref(channeld->gettables[i].content_type);
+  }
+  gpr_free(channeld->gettables);
+
   grpc_mdelem_unref(channeld->te_trailers);
   grpc_mdelem_unref(channeld->status_ok);
   grpc_mdelem_unref(channeld->status_not_found);
@@ -350,6 +358,6 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
 }
 
 const grpc_channel_filter grpc_http_server_filter = {
-    call_op,           channel_op,           sizeof(call_data),
-    init_call_elem,    destroy_call_elem,    sizeof(channel_data),
-    init_channel_elem, destroy_channel_elem, "http-server"};
+    call_op, channel_op, sizeof(call_data), init_call_elem, destroy_call_elem,
+    sizeof(channel_data), init_channel_elem, destroy_channel_elem,
+    "http-server"};
-- 
GitLab