]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/http: ensure headers are freed
authorTomas Krizek <tomas.krizek@nic.cz>
Wed, 30 Jun 2021 14:20:21 +0000 (16:20 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Thu, 29 Jul 2021 12:03:10 +0000 (14:03 +0200)
daemon/http.c

index 93a80deef6c9c991b9c16b5e33c453bb27e5c18f..e6b7d71503daf892be5c2597a8f418c560d0c098 100644 (file)
@@ -747,8 +747,18 @@ void http_free(struct http_ctx *ctx)
        if (!ctx)
                return;
 
+       /* Clean up any headers whose ownership may not have been transferred.
+        * This may happen when connection is abruptly ended (e.g. due to errors while
+        * processing HTTP stream. */
+       while (queue_len(ctx->streams) > 0) {
+               struct http_stream stream = queue_head(ctx->streams);
+               free_headers(stream.headers);
+               if (stream.headers == ctx->headers)
+                       ctx->headers = NULL;  // to prevent double-free
+               queue_pop(ctx->streams);
+       }
+
        http_cleanup_stream(ctx);
-       // TODO: queue_pop and check/free all headers (ownership may not have been transferred)
        queue_deinit(ctx->streams);
        nghttp2_session_del(ctx->h2);
        free(ctx);