From 02c12da2573d4d724fe8b1603b3814d93d17e75c Mon Sep 17 00:00:00 2001 From: Tomas Krizek Date: Wed, 30 Jun 2021 16:18:54 +0200 Subject: [PATCH] daemon/http: refactor freeing headers into function --- daemon/http.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/daemon/http.c b/daemon/http.c index 7472956fe..93a80deef 100644 --- a/daemon/http.c +++ b/daemon/http.c @@ -250,6 +250,18 @@ static void refuse_stream(nghttp2_session *h2, int32_t stream_id) h2, NGHTTP2_FLAG_NONE, stream_id, NGHTTP2_REFUSED_STREAM); } +static void free_headers(kr_http_header_array_t *headers) +{ + if (headers == NULL) + return; + + for (int i = 0; i < headers->len; i++) { + free(headers->at[i].name); + free(headers->at[i].value); + } + array_clear(*headers); + free(headers); +} /* Return the http ctx into a pristine state in which no stream is being processed. */ static void http_cleanup_stream(struct http_ctx *ctx) { @@ -257,15 +269,8 @@ static void http_cleanup_stream(struct http_ctx *ctx) ctx->current_method = HTTP_METHOD_NONE; free(ctx->uri_path); ctx->uri_path = NULL; - if (ctx->headers != NULL) { - for (int i = 0; i < ctx->headers->len; i++) { - free(ctx->headers->at[i].name); - free(ctx->headers->at[i].value); - } - array_clear(*ctx->headers); - free(ctx->headers); - ctx->headers = NULL; - } + free_headers(ctx->headers); + ctx->headers = NULL; } /* -- 2.47.2