[vlc-devel] [PATCH 03/25] image: use es_format_Copy() instead of es_format_Init() where possible

Francois Cartegnie fcvlcdev at free.fr
Mon Jul 10 17:09:46 CEST 2017


Le 10/07/2017 à 16:52, Steve Lhomme a écrit :
> We don't want to lose the palette. And if there's one there was potentially
> a double free when calling es_format_Clean() on the copied structure.
> ---
>  src/misc/image.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/src/misc/image.c b/src/misc/image.c
> index 20582ef1d6..c505b5bfcc 100644
> --- a/src/misc/image.c
> +++ b/src/misc/image.c
> @@ -646,9 +646,8 @@ static decoder_t *CreateDecoder( vlc_object_t *p_this, video_format_t *fmt )
>          return NULL;
>  
>      p_dec->p_module = NULL;
> -    es_format_Init( &p_dec->fmt_in, VIDEO_ES, fmt->i_chroma );
> +    es_format_Copy( &p_dec->fmt_in, fmt );
>      es_format_Init( &p_dec->fmt_out, VIDEO_ES, 0 );
> -    p_dec->fmt_in.video = *fmt;
>      p_dec->b_frame_drop_allowed = false;

Init() should always be called before Copy(), even if that does nothing.
I don't see the point of using an API if we need to be aware of what it
does internally.

Without Init -> Copy -> Clean cycles, we still write copy() internals
aware code and will have the same issues if something changes in struct
or code again.

Defining an InitFrom() which is aware of and just does Copy() also an
alternative.

Francois



More information about the vlc-devel mailing list