From 955e575f4e0a20a752e4fe1951f9d1107edd3925 Mon Sep 17 00:00:00 2001
From: kangenbo <kangenbo@huawei.com>
Date: Fri, 8 Mar 2019 12:06:11 -0500
Subject: [PATCH] http2: fix memory leaks on error-path

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

diff --git a/lib/http2.c b/lib/http2.c
index d769193..dfc780e 100644
--- a/lib/http2.c
+++ b/lib/http2.c
@@ -2060,8 +2060,11 @@ CURLcode Curl_http2_setup(struct connectdata *conn)
 
   stream->stream_id = -1;
 
-  if(!stream->header_recvbuf)
+  if(!stream->header_recvbuf) {
     stream->header_recvbuf = Curl_add_buffer_init();
+    if(!stream->header_recvbuf)
+      return CURLE_OUT_OF_MEMORY;
+  }
 
   if((conn->handler == &Curl_handler_http2_ssl) ||
      (conn->handler == &Curl_handler_http2))
@@ -2073,8 +2076,11 @@ CURLcode Curl_http2_setup(struct connectdata *conn)
     conn->handler = &Curl_handler_http2;
 
   result = Curl_http2_init(conn);
-  if(result)
+  if(result) {
+    Curl_add_buffer_free(stream->header_recvbuf);
+    stream->header_recvbuf = NULL;
     return result;
+  }
 
   infof(conn->data, "Using HTTP2, server supports multi-use\n");
   stream->upload_left = 0;
-- 
1.8.3.1

