diff mbox

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

Message ID 20191019150342.1490-1-jamrial@gmail.com
State Superseded
Headers show

Commit Message

James Almer Oct. 19, 2019, 3:03 p.m. UTC
avformat_free_context() expects AVFormatContext->internal to not be NULL.

Signed-off-by: James Almer <jamrial@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(-)

Comments

Andreas Rheinhardt Oct. 19, 2019, 3:30 p.m. UTC | #1
James Almer:
> avformat_free_context() expects AVFormatContext->internal to not be NULL.
> 
> Signed-off-by: James Almer <jamrial@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.
diff mbox

Patch

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;