From 468fca8ead4dd2096f4590d046383363de049d22 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 17 Mar 2020 14:19:43 -0400 Subject: [PATCH] TT#76711 error-proof codec_handler_free() Change-Id: Iaaf67bc21bcb904096a30497e817f5527fdf074d --- daemon/codec.c | 7 +++++-- daemon/media_player.c | 4 +--- include/codec.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/daemon/codec.c b/daemon/codec.c index 8198df5ad..bf0ca16fe 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -141,8 +141,11 @@ static void __codec_handler_free(void *pp) { __handler_shutdown(h); g_slice_free1(sizeof(*h), h); } -void codec_handler_free(struct codec_handler *handler) { - __codec_handler_free(handler); +void codec_handler_free(struct codec_handler **handler) { + if (!handler || !*handler) + return; + __codec_handler_free(*handler); + *handler = NULL; } static struct codec_handler *__handler_new(const struct rtp_payload_type *pt) { diff --git a/daemon/media_player.c b/daemon/media_player.c index 29ad5ea1d..0c4e7b346 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -61,9 +61,7 @@ static void media_player_shutdown(struct media_player *mp) { } mp->media = NULL; - if (mp->handler) - codec_handler_free(mp->handler); - mp->handler = NULL; + codec_handler_free(&mp->handler); if (mp->avioctx) { if (mp->avioctx->buffer) av_freep(&mp->avioctx->buffer); diff --git a/include/codec.h b/include/codec.h index 7561fc5c0..702a8956c 100644 --- a/include/codec.h +++ b/include/codec.h @@ -54,7 +54,7 @@ struct codec_handler *codec_handler_get(struct call_media *, int payload_type); void codec_handlers_free(struct call_media *); struct codec_handler *codec_handler_make_playback(const struct rtp_payload_type *src_pt, const struct rtp_payload_type *dst_pt, unsigned long ts); -void codec_handler_free(struct codec_handler *handler); +void codec_handler_free(struct codec_handler **handler); void ensure_codec_def(struct rtp_payload_type *pt, struct call_media *media); void codec_add_raw_packet(struct media_packet *mp);