[FFmpeg-devel,PR] avcodec/videotoolboxenc: fix leak when constant bitrate is not supported (PR #24850)
Commit Message
PR #24850 opened by Leo Bicknell (bicknell)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24850
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24850.patch
# Summary of changes
The CFNumber holding the bitrate was not released when the encoder
rejected kVTCompressionPropertyKey_ConstantBitRate. The early return
on that error path skipped the CFRelease that the normal path performs.
The leak has been present since the constant_bit_rate option was added
in 47b85c5a76.
# Testing
Built and ran `make fate` locally on macOS 27.0.1 (Apple M5 Max). The
Forgejo CI has no macOS runner, so it does not build this file.
# Disclosure
An AI assistant was used to help find and write this fix. I have reviewed
the change and tested it myself. This is my first PR to the ffmpeg project,
and found this bug while testing a more substantial submission I hope to
make in a few days. If I performed any of the process wrong please let me know
so I can correct before my larger submission.
>From 9284c1c30757d88fee7415bc9b5851faa768b103 Mon Sep 17 00:00:00 2001
From: Leo Bicknell <bicknell@ufp.org>
Date: Thu, 1 Oct 2026 18:23:03 -0400
Subject: [PATCH] avcodec/videotoolboxenc: fix leak when constant bitrate is
not supported
The CFNumber holding the bitrate was not released when the encoder
rejected kVTCompressionPropertyKey_ConstantBitRate.
Signed-off-by: Leo Bicknell <bicknell@ufp.org>
---
libavcodec/videotoolboxenc.c | 1 +
1 file changed, 1 insertion(+)
@@ -1267,6 +1267,7 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
bit_rate_num);
if (status == kVTPropertyNotSupportedErr) {
av_log(avctx, AV_LOG_ERROR, "-constant_bit_rate true is not supported by the encoder.\n");
+ CFRelease(bit_rate_num);
return AVERROR_EXTERNAL;
}
} else {