libavcodec/videotoolbox_vp9: Move av_malloc() to avoid memory leak
authorJiasheng Jiang <jiashengjiangcool@gmail.com>
Tue, 5 Aug 2025 19:31:15 +0000 (19:31 +0000)
committerMichael Niedermayer <michael@niedermayer.cc>
Thu, 14 Aug 2025 00:55:45 +0000 (02:55 +0200)
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 <jiashengjiangcool@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 8b4e6ccb13f10752bc5c2a963478c7f3764a0cfe)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/videotoolbox_vp9.c

index f5489854e387ddeee40500fe95d457941e669ca9..d870ea5d0fe9403c6c6a5a9d661dc742765ae7aa 100644 (file)
@@ -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;