From ad23ae196702cc3889a8c04a21273aa6a43aad75 Mon Sep 17 00:00:00 2001
From: Craig Tiller <ctiller@google.com>
Date: Fri, 4 Mar 2016 10:50:56 -0800
Subject: [PATCH] Unref writable streams on transport close to avoid leaks

---
 src/core/transport/chttp2_transport.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c
index ce54f7e6e8..19265252ca 100644
--- a/src/core/transport/chttp2_transport.c
+++ b/src/core/transport/chttp2_transport.c
@@ -432,6 +432,14 @@ static void close_transport_locked(grpc_exec_ctx *exec_ctx,
     if (t->ep) {
       allow_endpoint_shutdown_locked(exec_ctx, t);
     }
+
+    /* flush writable stream list to avoid dangling references */
+    grpc_chttp2_stream_global *stream_global;
+    grpc_chttp2_stream_writing *stream_writing;
+    while (grpc_chttp2_list_pop_writable_stream(
+        &t->global, &t->writing, &stream_global, &stream_writing)) {
+      GRPC_CHTTP2_STREAM_UNREF(exec_ctx, stream_global, "chttp2_writing");
+    }
   }
 }
 
@@ -617,7 +625,6 @@ static void unlock(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) {
 void grpc_chttp2_become_writable(grpc_chttp2_transport_global *transport_global,
                                  grpc_chttp2_stream_global *stream_global) {
   if (!TRANSPORT_FROM_GLOBAL(transport_global)->closed &&
-      !stream_global->write_closed &&
       grpc_chttp2_list_add_writable_stream(transport_global, stream_global)) {
     GRPC_CHTTP2_STREAM_REF(stream_global, "chttp2_writing");
   }
-- 
GitLab