diff mbox

[FFmpeg-devel,2/3] avcodec/videotoolbox: cosmetic change to simplify code with early return

Message ID 20170216182938.55393-2-ffmpeg@tmm1.net
State New
Headers show

Commit Message

Aman Karmani Feb. 16, 2017, 6:29 p.m. UTC
From: Aman Gupta <aman@tmm1.net>

---
 libavcodec/videotoolbox.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

wm4 Feb. 17, 2017, 6:01 a.m. UTC | #1
On Thu, 16 Feb 2017 10:29:37 -0800
Aman Gupta <ffmpeg@tmm1.net> wrote:

> From: Aman Gupta <aman@tmm1.net>
> 
> ---
>  libavcodec/videotoolbox.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
> index 1288aa5..9be7bee 100644
> --- a/libavcodec/videotoolbox.c
> +++ b/libavcodec/videotoolbox.c
> @@ -590,15 +590,16 @@ static int videotoolbox_default_init(AVCodecContext *avctx)
>  static void videotoolbox_default_free(AVCodecContext *avctx)
>  {
>      AVVideotoolboxContext *videotoolbox = avctx->hwaccel_context;
> +    if (!videotoolbox)
> +        return;
>  
> -    if (videotoolbox) {
> -        if (videotoolbox->cm_fmt_desc)
> -            CFRelease(videotoolbox->cm_fmt_desc);
> +    if (videotoolbox->cm_fmt_desc)
> +        CFRelease(videotoolbox->cm_fmt_desc);
>  
> -        if (videotoolbox->session) {
> -            VTDecompressionSessionInvalidate(videotoolbox->session);
> -            CFRelease(videotoolbox->session);
> -        }
> +    if (videotoolbox->session) {
> +        VTDecompressionSessionInvalidate(videotoolbox->session);
> +        CFRelease(videotoolbox->session);
> +        videotoolbox->session = NULL;
>      }
>  }
>  

LGTM
diff mbox

Patch

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 1288aa5..9be7bee 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -590,15 +590,16 @@  static int videotoolbox_default_init(AVCodecContext *avctx)
 static void videotoolbox_default_free(AVCodecContext *avctx)
 {
     AVVideotoolboxContext *videotoolbox = avctx->hwaccel_context;
+    if (!videotoolbox)
+        return;
 
-    if (videotoolbox) {
-        if (videotoolbox->cm_fmt_desc)
-            CFRelease(videotoolbox->cm_fmt_desc);
+    if (videotoolbox->cm_fmt_desc)
+        CFRelease(videotoolbox->cm_fmt_desc);
 
-        if (videotoolbox->session) {
-            VTDecompressionSessionInvalidate(videotoolbox->session);
-            CFRelease(videotoolbox->session);
-        }
+    if (videotoolbox->session) {
+        VTDecompressionSessionInvalidate(videotoolbox->session);
+        CFRelease(videotoolbox->session);
+        videotoolbox->session = NULL;
     }
 }