From c18904d8db9533c7b4cdc1a58fb8ef1aaf238a3b Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 30 Jul 2024 14:34:09 -0400 Subject: [PATCH] MT#55283 reduce usage of bencode_buffer_destroy_add Change-Id: I913f7df30d2dba46d6e44db74f55c43a2cd98444 --- daemon/call_interfaces.c | 20 +++++++------------- daemon/control_ng.c | 5 +++++ include/control_ng.h | 3 +++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index a143d7ab2..0356539e5 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -481,18 +481,14 @@ void calls_status_tcp(struct streambuf_stream *s) { -static void call_release_ref(void *p) { - call_t *c = p; - obj_put(c); -} -INLINE void call_bencode_hold_ref(call_t *c, bencode_buffer_t *buf) { +INLINE void call_bencode_hold_ref(call_t *c, ng_buffer *ngb) { /* We cannot guarantee that the "call" structures are still around at the time * when the bencode reply is finally read and sent out. Since we use scatter/gather * to avoid duplication of strings and stuff, we reserve a reference to the call * structs and have it released when the bencode buffer is destroyed. This is * necessary every time the bencode response may reference strings contained * within the call structs. */ - bencode_buffer_destroy_add(buf, call_release_ref, obj_get(c)); + ngb->call = obj_get(c); } INLINE void str_hyphenate(str *s_ori) { @@ -2125,7 +2121,6 @@ static const char *call_offer_answer_ng(ng_parser_ctx_t *ctx, enum call_opmode o struct call_monologue * monologues[2]; int ret; g_auto(sdp_ng_flags) flags; - struct sdp_chopper *chopper; bencode_item_t *output = ctx->resp; call_ng_process_flags(&flags, ctx, opmode); @@ -2196,7 +2191,7 @@ static const char *call_offer_answer_ng(ng_parser_ctx_t *ctx, enum call_opmode o /* At least the random ICE strings are contained within the call struct, so we * need to hold a ref until we're done sending the reply */ - call_bencode_hold_ref(call, &ctx->ngbuf->buffer); + call_bencode_hold_ref(call, ctx->ngbuf); errstr = "Invalid dialogue association"; if (call_get_mono_dialogue(monologues, call, &flags.from_tag, &flags.to_tag, @@ -2213,8 +2208,7 @@ static const char *call_offer_answer_ng(ng_parser_ctx_t *ctx, enum call_opmode o from_ml->tagtype = TO_TAG; } - chopper = sdp_chopper_new(&sdp); - bencode_buffer_destroy_add(output->buffer, (free_func_t) sdp_chopper_destroy, chopper); + struct sdp_chopper *chopper = ctx->ngbuf->chopper = sdp_chopper_new(&sdp); if (flags.drop_traffic_start) { CALL_SET(call, DROP_TRAFFIC); @@ -2690,7 +2684,7 @@ void ng_call_stats(ng_parser_ctx_t *ctx, call_t *call, const str *fromtag, const if (!ctx) goto stats; - call_bencode_hold_ref(call, &ctx->ngbuf->buffer); + call_bencode_hold_ref(call, ctx->ngbuf); ctx->parser->dict_add_int(ctx->resp, "created", call->created.tv_sec); ctx->parser->dict_add_int(ctx->resp, "created_us", call->created.tv_usec); @@ -3680,7 +3674,7 @@ const char *call_publish_ng(ng_parser_ctx_t *ctx, ret = sdp_create(&sdp_out, ml, &flags); if (!ret) { save_last_sdp(ml, &sdp_in, &parsed, &streams); - bencode_buffer_destroy_add(ctx->resp->buffer, g_free, sdp_out.s); + ctx->ngbuf->sdp_out = sdp_out.s; ctx->parser->dict_add_str(ctx->resp, "sdp", &sdp_out); sdp_out = STR_NULL; // ownership passed to output } @@ -3743,7 +3737,7 @@ const char *call_subscribe_request_ng(ng_parser_ctx_t *ctx) { /* place return output SDP */ if (sdp_out.len) { - bencode_buffer_destroy_add(output->buffer, g_free, sdp_out.s); + ctx->ngbuf->sdp_out = sdp_out.s; ctx->parser->dict_add_str(output, "sdp", &sdp_out); sdp_out = STR_NULL; /* ownership passed to output */ } diff --git a/daemon/control_ng.c b/daemon/control_ng.c index 7aa0aad89..e0507eab3 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -303,6 +303,11 @@ static void __ng_buffer_free(void *p) { obj_put_o(ngbuf->ref); if (ngbuf->json) g_object_unref(ngbuf->json); + if (ngbuf->chopper) + sdp_chopper_destroy(ngbuf->chopper); + g_free(ngbuf->sdp_out); + if (ngbuf->call) + obj_put(ngbuf->call); } ng_buffer *ng_buffer_new(struct obj *ref) { diff --git a/include/control_ng.h b/include/control_ng.h index 3e970c039..e7548ec32 100644 --- a/include/control_ng.h +++ b/include/control_ng.h @@ -62,6 +62,9 @@ struct ng_buffer { bencode_buffer_t buffer; struct obj *ref; JsonParser *json; + struct sdp_chopper *chopper; + char *sdp_out; + struct call *call; };