Memory leakage when rejecting HTTP2 server push stream #1229

zelinchen opened this Issue Jan 26, 2017 · 2 comments


None yet

2 participants


I did this

I've copied the code form And just return CURL_PUSH_DENY in server_push_callback() to test if can reject server push steam. All is fine except that valgrind complains about memory leakage.

I expected the following

No memory leakage even rejecting server push stream.

curl/libcurl version

libcurl: curl-7_52_1
nghttp2: v1.18.1

operating system

Fedora 19, x86_64

I think better to destroy the following 2 pointers when failure or rejecting steam.

diff --git a/lib/http2.c b/lib/http2.c
index 4cc17ba..fa7bdb6 100644
--- a/lib/http2.c
+++ b/lib/http2.c
@@ -418,6 +418,9 @@ static int push_promise(struct Curl_easy *data,

     if(rv) {
       /* denied, kill off the new handle again */
+      Curl_add_buffer_free(
+        ((struct HTTP *)(newhandle->req.protop))->header_recvbuf);
+      free(newhandle->req.protop);
       goto fail;
@@ -432,6 +435,9 @@ static int push_promise(struct Curl_easy *data,
     rc = Curl_multi_add_perform(data->multi, newhandle, conn);
     if(rc) {
       infof(data, "failed to add handle to multi\n");
+      Curl_add_buffer_free(
+        ((struct HTTP *)(newhandle->req.protop))->header_recvbuf);
+      free(newhandle->req.protop);
       rv = 1;
       goto fail;
@bagder bagder self-assigned this Feb 12, 2017
bagder commented Feb 12, 2017


@bagder bagder added a commit that closed this issue Feb 13, 2017
@bagder bagder http2: fix memory-leak when denying push streams
Fixes #1229
@bagder bagder closed this in bde1e2e Feb 13, 2017
bagder commented Feb 13, 2017

Thanks a lot. As you can see I opted to solving the problem slightly different with the hope that this should make it less likely to happen again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment