From d5275c5d98111698555152849572f6b973e8232a Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 14 Aug 2025 13:23:52 -0400 Subject: [PATCH] MT#55283 clarify _destroy_ptr Change-Id: Ib453648d21e907bffd7120a9c9b50275f7bf0846 (cherry picked from commit 08239c95106b3f888beeb4672f3f86e9928981e1) (cherry picked from commit 48999b1fdfa471c15975d047eb45bee98e94726e) --- daemon/media_socket.c | 7 +++---- lib/containers.h | 9 +++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 590082369..7e5177312 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1522,7 +1522,7 @@ typedef struct { } kernelize_state; static void kernelize_state_clear(kernelize_state *s) { - rtp_stats_arr_destroy_ptr(s->payload_types); + rtp_stats_arr_destroy_ptr(&s->payload_types); t_queue_clear_full(&s->outputs, (void (*)(struct rtpengine_destination_info *)) g_free); // should always be empty } @@ -1885,8 +1885,7 @@ static void kernelize(struct packet_stream *stream) { // record number of RTP destinations up to now unsigned int num_rtp_dests = s.reti.num_destinations; // ignore RTP payload types - rtp_stats_arr_destroy_ptr(s.payload_types); - s.payload_types = NULL; + rtp_stats_arr_destroy_ptr(&s.payload_types); for (__auto_type l = stream->rtcp_sinks.head; l; l = l->next) { struct sink_handler *sh = l->data; bool ok = kernelize_one_sink_handler(&s, stream, sh); @@ -1925,7 +1924,7 @@ no_kernel: restart: // handle detected deadlock - rtp_stats_arr_destroy_ptr(s.payload_types); + rtp_stats_arr_destroy_ptr(&s.payload_types); while ((redi = t_queue_pop_head(&s.outputs))) g_free(redi); diff --git a/lib/containers.h b/lib/containers.h index 3307b5c91..a0945d303 100644 --- a/lib/containers.h +++ b/lib/containers.h @@ -444,11 +444,16 @@ static inline void g_queue_clear_full(GQueue *q, GDestroyNotify free_func) { static inline type_name *type_name##_new(void) { \ return type_name##_new_sized(0); \ } \ - static inline void type_name##_destroy_ptr(type_name *A) { \ + static inline void type_name##_destroy(type_name *A) { \ if (A) \ g_ptr_array_free(&(A)->a, TRUE); \ } \ - G_DEFINE_AUTOPTR_CLEANUP_FUNC(type_name, type_name##_destroy_ptr) + static inline void type_name##_destroy_ptr(type_name **A) { \ + if (*A) \ + g_ptr_array_free(&(*A)->a, TRUE); \ + *A = NULL; \ + } \ + G_DEFINE_AUTOPTR_CLEANUP_FUNC(type_name, type_name##_destroy) #define TYPED_GPTRARRAY(type_name, contained_type) \ TYPED_GPTRARRAY_FULL(type_name, contained_type, NULL)