[FFmpeg-devel] [PATCH] avformat/options: don't call avformat_free_context() within avformat_alloc_context()

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Sat Oct 19 18:30:00 EEST 2019


James Almer:
> avformat_free_context() expects AVFormatContext->internal to not be NULL.
> 
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
> Alternatively we could check for internal != NULL in avformat_free_context()
> before dereferencing it, but i don't think it makes sense calling that function
> at all if the AVFormatContext wasn't even fully allocated to begin with.
> 
>  libavformat/options.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/options.c b/libavformat/options.c
> index c188c23506..9a6deed0df 100644
> --- a/libavformat/options.c
> +++ b/libavformat/options.c
> @@ -150,7 +150,7 @@ AVFormatContext *avformat_alloc_context(void)
>  
>      ic->internal = av_mallocz(sizeof(*ic->internal));
>      if (!ic->internal) {
> -        avformat_free_context(ic);
> +        av_free(ic);
>          return NULL;
>      }
>      ic->internal->offset = AV_NOPTS_VALUE;
> 
avformat_get_context_defaults() calls av_opt_set_defaults and this
duplicates the default string for every option of type
AV_OPT_TYPE_STRING.* This effectively leaks the default value of
dump_separator (namely ", ").

- Andreas

*: And yet av_opt_set_defaults ignores the return value of said
allocation and returns void. Strange.


More information about the ffmpeg-devel mailing list