]> granicus.if.org Git - curl/commitdiff
http2: http_done: don't free already-freed push headers
authorDaniel Stenberg <daniel@haxx.se>
Tue, 17 Nov 2015 08:47:58 +0000 (09:47 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 17 Nov 2015 08:47:58 +0000 (09:47 +0100)
The push headers are freed after the push callback has been invoked,
meaning this code should only free the headers if the callback was never
invoked and thus the headers weren't freed at that time.

Reported-by: Davey Shafik
lib/http.c

index 12a70d6deb582e37b0f787a1e6211f82b313760b..eaa5f949ceb25b0fb3cce48409b35580182a07f0 100644 (file)
@@ -1480,11 +1480,14 @@ CURLcode Curl_http_done(struct connectdata *conn,
     DEBUGF(infof(data, "free header_recvbuf!!\n"));
     Curl_add_buffer_free(http->header_recvbuf);
     http->header_recvbuf = NULL; /* clear the pointer */
-    for(; http->push_headers_used > 0; --http->push_headers_used) {
-      free(http->push_headers[http->push_headers_used - 1]);
+    if(http->push_headers) {
+      /* if they weren't used and then freed before */
+      for(; http->push_headers_used > 0; --http->push_headers_used) {
+        free(http->push_headers[http->push_headers_used - 1]);
+      }
+      free(http->push_headers);
+      http->push_headers = NULL;
     }
-    free(http->push_headers);
-    http->push_headers = NULL;
   }
   if(http->stream_id) {
     nghttp2_session_set_stream_user_data(httpc->h2, http->stream_id, 0);