[vlc-commits] avcodec: vaapi: check vlc_va_sys_t creation early

Steve Lhomme git at videolan.org
Thu Jun 20 10:03:27 CEST 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Wed Jun 19 15:10:24 2019 +0200| [c0dc2e78533a9ff34dba200261013401967c2ca4] | committer: Steve Lhomme

avcodec: vaapi: check vlc_va_sys_t creation early

No need for extra checks later.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c0dc2e78533a9ff34dba200261013401967c2ca4
---

 modules/codec/avcodec/vaapi.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c
index 730b788372..54e8f16cb2 100644
--- a/modules/codec/avcodec/vaapi.c
+++ b/modules/codec/avcodec/vaapi.c
@@ -151,10 +151,14 @@ static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     if (pix_fmt != AV_PIX_FMT_VAAPI_VLD || p_sys == NULL)
         return VLC_EGENERIC;
 
+    vlc_va_sys_t *sys = malloc(sizeof *sys);
+    if (unlikely(sys == NULL))
+        return VLC_ENOMEM;
+    memset(sys, 0, sizeof (*sys));
+
     vlc_object_t *o = VLC_OBJECT(va);
 
     int ret = VLC_EGENERIC;
-    vlc_va_sys_t *sys = NULL;
 
     /* The picture must be allocated by the vout */
     VADisplay va_dpy;
@@ -173,14 +177,6 @@ static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     if (GetVaProfile(ctx, fmt, &i_profile, &i_vlc_chroma, &count) != VLC_SUCCESS)
         goto error;
 
-    sys = malloc(sizeof *sys);
-    if (unlikely(sys == NULL))
-    {
-        ret = VLC_ENOMEM;
-        goto error;
-    }
-    memset(sys, 0, sizeof (*sys));
-
     /* */
     sys->dec_device = dec_device;
     sys->hw_ctx.display = va_dpy;
@@ -209,14 +205,11 @@ static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     return VLC_SUCCESS;
 
 error:
-    if (sys != NULL)
-    {
-        if (sys->hw_ctx.context_id != VA_INVALID_ID)
-            vlc_vaapi_DestroyContext(o, sys->hw_ctx.display, sys->hw_ctx.context_id);
-        if (sys->hw_ctx.config_id != VA_INVALID_ID)
-            vlc_vaapi_DestroyConfig(o, sys->hw_ctx.display, sys->hw_ctx.config_id);
-        free(sys);
-    }
+    if (sys->hw_ctx.context_id != VA_INVALID_ID)
+        vlc_vaapi_DestroyContext(o, sys->hw_ctx.display, sys->hw_ctx.context_id);
+    if (sys->hw_ctx.config_id != VA_INVALID_ID)
+        vlc_vaapi_DestroyConfig(o, sys->hw_ctx.display, sys->hw_ctx.config_id);
+    free(sys);
     vlc_decoder_device_Release(dec_device);
     return ret;
 }



More information about the vlc-commits mailing list