From d26605818339acb190572a5c4291945160063ff0 Mon Sep 17 00:00:00 2001
From: kangenbo <kangenbo@huawei.com>
Date: Mon, 18 Mar 2019 13:41:26 -0400
Subject: [PATCH] 0101

---
 lib/http2.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/http2.c b/lib/http2.c
index dfc780e..eb395f9 100644
--- a/lib/http2.c
+++ b/lib/http2.c
@@ -1085,12 +1085,8 @@ void Curl_http2_done(struct connectdata *conn, bool premature)
   struct HTTP *http = data->req.protop;
   struct http_conn *httpc = &conn->proto.httpc;
 
-  if(!httpc->h2) /* not HTTP/2 ? */
-    return;
-
-  if(data->state.drain)
-    drained_transfer(data, httpc);
-
+  /* there might be allocated resources done before this got the 'h2' pointer
+     setup */
   if(http->header_recvbuf) {
     Curl_add_buffer_free(http->header_recvbuf);
     http->header_recvbuf = NULL; /* clear the pointer */
@@ -1106,6 +1102,12 @@ void Curl_http2_done(struct connectdata *conn, bool premature)
     }
   }
 
+  if(!httpc->h2) /* not HTTP/2 ? */
+    return;
+
+  if(data->state.drain)
+    drained_transfer(data, httpc);
+
   if(premature) {
     /* RST_STREAM */
     if(!nghttp2_submit_rst_stream(httpc->h2, NGHTTP2_FLAG_NONE,
-- 
1.8.3.1

