[vlc-commits] mediacodec: fix cleanup on error

Romain Vimont git at videolan.org
Thu Dec 19 10:51:18 CET 2019


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Thu Dec 12 22:21:24 2019 +0100| [67b0085237b7821452541ad6feddfbe10aa491ef] | committer: Thomas Guillem

mediacodec: fix cleanup on error

In case p_surface is NULL, vlc_video_context_Release() was called
immediately.

This caused 2 problems:
 - it indirectly uses avctx->dec_opaque, which is not initialized yet;
 - it indirectly calls CleanDecoder a first time, before it is called
   again after "goto bailout;".

To fix the problem, change the initialization order not to leak the
video context, and let the cleanup in "bailout" do its job.

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

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

 modules/codec/omxil/mediacodec.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index 2f99ea93a2..c55fd23e6f 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -658,6 +658,14 @@ CreateVideoContext(decoder_t *p_dec)
     else
         id = AWindow_Video;
 
+    p_sys->video.p_surface = AWindowHandler_getANativeWindow(awh, id);
+    p_sys->video.p_jsurface = AWindowHandler_getSurface(awh, id);
+    if (!p_sys->video.p_surface)
+    {
+        msg_Err(p_dec, "Could not find a valid ANativeWindow");
+        return VLC_EGENERIC;
+    }
+
     static const struct vlc_video_context_operations ops =
     {
         .destroy = CleanFromVideoContext,
@@ -670,16 +678,6 @@ CreateVideoContext(decoder_t *p_dec)
     if (!p_sys->video.ctx)
         return VLC_EGENERIC;
 
-    p_sys->video.p_surface = AWindowHandler_getANativeWindow(awh, id);
-    p_sys->video.p_jsurface = AWindowHandler_getSurface(awh, id);
-    if (!p_sys->video.p_surface)
-    {
-        msg_Err(p_dec, "Could not find a valid ANativeWindow");
-        vlc_video_context_Release(p_sys->video.ctx);
-        p_sys->video.ctx = NULL;
-        return VLC_EGENERIC;
-    }
-
     android_video_context_t *avctx =
         vlc_video_context_GetPrivate(p_sys->video.ctx, VLC_VIDEO_CONTEXT_AWINDOW);
     avctx->id = id;



More information about the vlc-commits mailing list