[vlc-commits] [Git][videolan/vlc][master] videotoolbox: refactor error path with goto
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Thu Nov 10 18:57:31 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
2f08df59 by Alexandre Janniaux at 2022-11-10T18:42:34+00:00
videotoolbox: refactor error path with goto
Using goto here provides a location to avoid repetitive release calls,
ensuring everything is released at first look.
- - - - -
1 changed file:
- modules/codec/videotoolbox.c
Changes:
=====================================
modules/codec/videotoolbox.c
=====================================
@@ -1151,6 +1151,10 @@ static int StartVideoToolbox(decoder_t *p_dec)
{
decoder_sys_t *p_sys = p_dec->p_sys;
+ /* Initialized to NULL for error handling */
+ CFMutableDictionaryRef destinationPixelBufferAttributes = NULL;
+ CFMutableDictionaryRef decoderConfiguration = NULL;
+
/* Late starts */
if (p_sys->pf_late_start && p_sys->pf_late_start(p_dec))
{
@@ -1163,19 +1167,16 @@ static int StartVideoToolbox(decoder_t *p_dec)
return VLC_EGENERIC;
/* destination pixel buffer attributes */
- CFMutableDictionaryRef destinationPixelBufferAttributes = cfdict_create(0);
+ destinationPixelBufferAttributes = cfdict_create(0);
if (destinationPixelBufferAttributes == NULL)
return VLC_EGENERIC;
- CFMutableDictionaryRef decoderConfiguration =
+ decoderConfiguration =
CreateSessionDescriptionFormat(p_dec,
p_dec->fmt_out.video.i_sar_num,
p_dec->fmt_out.video.i_sar_den);
if (decoderConfiguration == NULL)
- {
- CFRelease(destinationPixelBufferAttributes);
- return VLC_EGENERIC;
- }
+ goto error;
/* create video format description */
OSStatus status = CMVideoFormatDescriptionCreate(
@@ -1187,10 +1188,8 @@ static int StartVideoToolbox(decoder_t *p_dec)
&p_sys->videoFormatDescription);
if (status)
{
- CFRelease(destinationPixelBufferAttributes);
- CFRelease(decoderConfiguration);
msg_Err(p_dec, "video format description creation failed (%i)", (int)status);
- return VLC_EGENERIC;
+ goto error;
}
#if !TARGET_OS_IPHONE
@@ -1239,6 +1238,15 @@ static int StartVideoToolbox(decoder_t *p_dec)
return VLC_EGENERIC;
return VLC_SUCCESS;
+
+error:
+ if (decoderConfiguration != NULL)
+ CFRelease(decoderConfiguration);
+
+ if (destinationPixelBufferAttributes != NULL)
+ CFRelease(destinationPixelBufferAttributes);
+
+ return VLC_EGENERIC;
}
static void StopVideoToolbox(decoder_t *p_dec, bool closing)
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/2f08df594a8e330087afebc528f5887ecabc4dda
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/2f08df594a8e330087afebc528f5887ecabc4dda
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list