From bdd66fe730c6454315fd88d06a3dc097975e6442 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 29 Jul 2024 09:37:09 -0400 Subject: [PATCH] MT#55283 move JsonParser into ngbuf Use ngbuf's free function to destroy the JSON parser instead of the callback for the bencode_buffer object. Change-Id: I7eccf7284f55b34ef1a4800017ea1a4519f42bbc --- daemon/control_ng.c | 9 +++++---- include/control_ng.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/daemon/control_ng.c b/daemon/control_ng.c index ca97107de..7aa0aad89 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -301,6 +301,8 @@ static void __ng_buffer_free(void *p) { bencode_buffer_free(&ngbuf->buffer); if (ngbuf->ref) obj_put_o(ngbuf->ref); + if (ngbuf->json) + g_object_unref(ngbuf->json); } ng_buffer *ng_buffer_new(struct obj *ref) { @@ -346,12 +348,11 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons /* JSON */ else if (data->s[0] == '{') { parser_ctx.parser = &ng_parser_json; - JsonParser *json = json_parser_new(); - bencode_buffer_destroy_add(&parser_ctx.ngbuf->buffer, g_object_unref, json); + parser_ctx.ngbuf->json = json_parser_new(); errstr = "Failed to parse JSON document"; - if (!json_parser_load_from_data(json, data->s, data->len, NULL)) + if (!json_parser_load_from_data(parser_ctx.ngbuf->json, data->s, data->len, NULL)) goto err_send; - parser_ctx.req = bencode_convert_json(&parser_ctx.ngbuf->buffer, json); + parser_ctx.req = bencode_convert_json(&parser_ctx.ngbuf->buffer, parser_ctx.ngbuf->json); errstr = "Could not decode bencode dictionary"; if (!parser_ctx.req || parser_ctx.req->type != BENCODE_DICTIONARY) goto err_send; diff --git a/include/control_ng.h b/include/control_ng.h index 54997d9e2..3e970c039 100644 --- a/include/control_ng.h +++ b/include/control_ng.h @@ -61,6 +61,7 @@ struct ng_buffer { struct obj obj; bencode_buffer_t buffer; struct obj *ref; + JsonParser *json; };