From bbac13c54a9e33eeca83a5da9beecbec253133ed Mon Sep 17 00:00:00 2001 From: Jiasheng Jiang Date: Tue, 5 Aug 2025 19:31:15 +0000 Subject: [PATCH] libavcodec/videotoolbox_vp9: Move av_malloc() to avoid memory leak Move av_malloc() after the check for subsampling to avoid memory leak if subsampling < 0 and av_malloc() succeeds. Fixes: a41a2efc85 ("lavc/videotoolbox: add VP9 hardware acceleration") Signed-off-by: Jiasheng Jiang Signed-off-by: Michael Niedermayer (cherry picked from commit 8b4e6ccb13f10752bc5c2a963478c7f3764a0cfe) Signed-off-by: Michael Niedermayer --- libavcodec/videotoolbox_vp9.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/videotoolbox_vp9.c b/libavcodec/videotoolbox_vp9.c index f5489854e3..d870ea5d0f 100644 --- a/libavcodec/videotoolbox_vp9.c +++ b/libavcodec/videotoolbox_vp9.c @@ -70,12 +70,12 @@ CFDataRef ff_videotoolbox_vpcc_extradata_create(AVCodecContext *avctx) uint8_t *vt_extradata; int subsampling = get_vpx_chroma_subsampling(avctx->sw_pix_fmt, avctx->chroma_sample_location); - vt_extradata_size = 1 + 3 + 6 + 2; - vt_extradata = av_malloc(vt_extradata_size); - if (subsampling < 0) return NULL; + vt_extradata_size = 1 + 3 + 6 + 2; + vt_extradata = av_malloc(vt_extradata_size); + if (!vt_extradata) return NULL;