From 7a205ff3bb43ff3e6dd73501c7a6084f0b080602 Mon Sep 17 00:00:00 2001 From: Harish Mahendrakar Date: Fri, 10 Jul 2026 09:38:38 -0700 Subject: [PATCH] Invoke ih264d_free_dynamic_bufs() in ih264d_allocate_dynamic_bufs() In order do this, moved freeing of dynamic bitstream buffer outside free_dynamic_bufs() call. This allocation is not done inside allocate_dynamic_bufs() and hence shouldn't be freed in free_dynamic_bufs(). This will ensure that any memory that is allocated before and not yet freed, will be freed. This is done as a precaution to ensure there are no leaks. --- decoder/ih264d_api.c | 2 ++ decoder/ih264d_utils.c | 6 ++++-- decoder/svc/isvcd_utils.c | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/decoder/ih264d_api.c b/decoder/ih264d_api.c index 25f03daa..20cba70b 100644 --- a/decoder/ih264d_api.c +++ b/decoder/ih264d_api.c @@ -1185,6 +1185,7 @@ void ih264d_init_decoder(void * ps_dec_params) memset(ps_dec->pv_mv_buf_mgr, 0, size); /* Free any dynamic buffers that are allocated */ + PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_bits_buf_dynamic); ih264d_free_dynamic_bufs(ps_dec); { @@ -3649,6 +3650,7 @@ WORD32 ih264d_delete(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op) ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle); UNUSED(ps_ip); ps_op->s_ivd_delete_op_t.u4_error_code = 0; + PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_bits_buf_dynamic); ih264d_free_dynamic_bufs(ps_dec); ih264d_free_static_bufs(dec_hdl); return IV_SUCCESS; diff --git a/decoder/ih264d_utils.c b/decoder/ih264d_utils.c index 1f0e13fa..4b07ec33 100644 --- a/decoder/ih264d_utils.c +++ b/decoder/ih264d_utils.c @@ -1931,6 +1931,10 @@ WORD16 ih264d_allocate_dynamic_bufs(dec_struct_t * ps_dec) UWORD32 u4_luma_size, u4_chroma_size; void *pv_mem_ctxt = ps_dec->pv_mem_ctxt; + /* Free any dynamic buffers that are allocated earlier. As ps_dec is memset to zero */ + /* at the beginning, it is safe to call this even if no memory was allocated earlier */ + ih264d_free_dynamic_bufs(ps_dec); + size = u4_total_mbs; pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); RETURN_IF((NULL == pv_buf), IV_FAIL); @@ -2285,8 +2289,6 @@ WORD16 ih264d_allocate_dynamic_bufs(dec_struct_t * ps_dec) */ WORD16 ih264d_free_dynamic_bufs(dec_struct_t * ps_dec) { - PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_bits_buf_dynamic); - PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_deblk_pic); PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_dec_mb_map); PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_recon_mb_map); diff --git a/decoder/svc/isvcd_utils.c b/decoder/svc/isvcd_utils.c index 94661c55..19bd88ae 100644 --- a/decoder/svc/isvcd_utils.c +++ b/decoder/svc/isvcd_utils.c @@ -85,6 +85,7 @@ WORD16 isvcd_free_dynamic_bufs(svc_dec_lyr_struct_t *ps_svc_lyr_dec) WORD32 i; dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec; /* Free any avc dynamic buffers that are allocated */ + PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_bits_buf_dynamic); ih264d_free_dynamic_bufs(ps_dec); PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pu1_crop_wnd_flag); PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->ps_inter_lyr_mb_prms_base);