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

Steve Lhomme robux4 at ycbcr.xyz
Fri Dec 13 11:27:34 CET 2019


LGTM

On 2019-12-13 11:12, Romain Vimont wrote:
> 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
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
> 


More information about the vlc-devel mailing list