[vlc-devel] [PATCH v2] mediacodec: fix cleanup on error

Romain Vimont rom1v at videolabs.io
Fri Dec 13 11:12:58 CET 2019


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.
---
 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;
-- 
2.24.0



More information about the vlc-devel mailing list