diff mbox series

[FFmpeg-devel,2/2] avdevice/decklink_dec: fix leaks on error

Message ID D43YWTLYCN6V.ON7GEQLHAU0D@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avdevice/decklink_dec: fix leak on error | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Marvin Scholz Sept. 12, 2024, 2:58 a.m. UTC
In case of errors in this function, the allocated context
was not properly freed in several cases.
---
 libavdevice/decklink_dec.cpp | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 9a817daf187..418701e4e0c 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -1112,32 +1112,35 @@  av_cold int ff_decklink_read_header(AVFormatContext *avctx)
         case 8:
         case 16:
             break;
         default:
             av_log(avctx, AV_LOG_ERROR, "Value of channels option must be one of 2, 8 or 16\n");
-            return AVERROR(EINVAL);
+            ret = AVERROR(EINVAL);
+            goto error;
     }
 
     /* Check audio bit depth option for valid values: 16 or 32 */
     switch (cctx->audio_depth) {
         case 16:
         case 32:
             break;
         default:
             av_log(avctx, AV_LOG_ERROR, "Value for audio bit depth option must be either 16 or 32\n");
-            return AVERROR(EINVAL);
+            ret = AVERROR(EINVAL);
+            goto error;
     }
 
     /* List available devices. */
     if (ctx->list_devices) {
         ff_decklink_list_devices_legacy(avctx, 1, 0);
-        return AVERROR_EXIT;
+        ret = AVERROR_EXIT;
+        goto error;
     }
 
     ret = ff_decklink_init_device(avctx, avctx->url);
     if (ret < 0)
-        return ret;
+        goto error;
 
     /* Get input device. */
     if (ctx->dl->QueryInterface(IID_IDeckLinkInput, (void **) &ctx->dli) != S_OK) {
         av_log(avctx, AV_LOG_ERROR, "Could not open input device from '%s'\n",
                avctx->url);
@@ -1334,10 +1337,11 @@  av_cold int ff_decklink_read_header(AVFormatContext *avctx)
 
     return 0;
 
 error:
     ff_decklink_cleanup(avctx);
+    av_freep(&cctx->ctx);
     return ret;
 }
 
 int ff_decklink_read_packet(AVFormatContext *avctx, AVPacket *pkt)
 {