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

index 7472956fe4ea9b79b773b6b25b5c963563bf4ee0..93a80deef6c9c991b9c16b5e33c453bb27e5c18f 100644 (file)
@@ -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;
 }
 
 /*