From: Tomas Krizek Date: Wed, 30 Jun 2021 14:20:21 +0000 (+0200) Subject: daemon/http: ensure headers are freed X-Git-Tag: v5.4.0~1^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e03541f9bc98c8b1f7477721afa7948e9eacd76;p=thirdparty%2Fknot-resolver.git daemon/http: ensure headers are freed --- 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);