From 8e03541f9bc98c8b1f7477721afa7948e9eacd76 Mon Sep 17 00:00:00 2001 From: Tomas Krizek Date: Wed, 30 Jun 2021 16:20:21 +0200 Subject: [PATCH] daemon/http: ensure headers are freed --- daemon/http.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/daemon/http.c b/daemon/http.c index 93a80deef..e6b7d7150 100644 --- a/daemon/http.c +++ b/daemon/http.c @@ -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); -- 2.47.2