diff mbox series

[FFmpeg-devel,08/11] avformat/dashenc: Fix leak of AVFormatContext on error

Message ID 20200107135549.22581-8-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,01/11] avformat/avformat: Update AVInputFormat.read_packet documentation | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Andreas Rheinhardt Jan. 7, 2020, 1:55 p.m. UTC
The Dash muxer uses submuxers and when one such submuxer has been allocated,
it is initially only stored in a temporary variable. Therefore it leaks
if an error happens between the allocation and storing it permanently.
This commit changes this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/dashenc.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Jeyapal, Karthick Jan. 7, 2020, 4:03 p.m. UTC | #1
On 1/7/20 7:25 PM, Andreas Rheinhardt wrote:
> The Dash muxer uses submuxers and when one such submuxer has been allocated,
> it is initially only stored in a temporary variable. Therefore it leaks
> if an error happens between the allocation and storing it permanently.
> This commit changes this.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/dashenc.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> index b84736881f..dab7010179 100644
> --- a/libavformat/dashenc.c
> +++ b/libavformat/dashenc.c
> @@ -1225,10 +1225,6 @@ static int dash_init(AVFormatContext *s)
>          dict_copy_entry(&as->metadata, s->streams[i]->metadata, "language");
>          dict_copy_entry(&as->metadata, s->streams[i]->metadata, "role");
>  
> -        ctx = avformat_alloc_context();
> -        if (!ctx)
> -            return AVERROR(ENOMEM);
> -
>          if (c->init_seg_name) {
>              os->init_seg_name = av_strireplace(c->init_seg_name, "$ext$", os->extension_name);
>              if (!os->init_seg_name)
> @@ -1261,10 +1257,13 @@ static int dash_init(AVFormatContext *s)
>              }
>          }
>  
> +        os->ctx = ctx = avformat_alloc_context();
> +        if (!ctx)
> +            return AVERROR(ENOMEM);
> +
>          ctx->oformat = av_guess_format(os->format_name, NULL, NULL);
>          if (!ctx->oformat)
>              return AVERROR_MUXER_NOT_FOUND;
> -        os->ctx = ctx;
>          ctx->interrupt_callback    = s->interrupt_callback;
>          ctx->opaque                = s->opaque;
>          ctx->io_close              = s->io_close;
LGTM

Regards,
Karthick
Michael Niedermayer Jan. 8, 2020, 12:38 a.m. UTC | #2
On Tue, Jan 07, 2020 at 04:03:15PM +0000, Jeyapal, Karthick wrote:
> 
> On 1/7/20 7:25 PM, Andreas Rheinhardt wrote:
> > The Dash muxer uses submuxers and when one such submuxer has been allocated,
> > it is initially only stored in a temporary variable. Therefore it leaks
> > if an error happens between the allocation and storing it permanently.
> > This commit changes this.
> >
> > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> > ---
> >  libavformat/dashenc.c | 9 ++++-----
> >  1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> > index b84736881f..dab7010179 100644
> > --- a/libavformat/dashenc.c
> > +++ b/libavformat/dashenc.c
> > @@ -1225,10 +1225,6 @@ static int dash_init(AVFormatContext *s)
> >          dict_copy_entry(&as->metadata, s->streams[i]->metadata, "language");
> >          dict_copy_entry(&as->metadata, s->streams[i]->metadata, "role");
> >  
> > -        ctx = avformat_alloc_context();
> > -        if (!ctx)
> > -            return AVERROR(ENOMEM);
> > -
> >          if (c->init_seg_name) {
> >              os->init_seg_name = av_strireplace(c->init_seg_name, "$ext$", os->extension_name);
> >              if (!os->init_seg_name)
> > @@ -1261,10 +1257,13 @@ static int dash_init(AVFormatContext *s)
> >              }
> >          }
> >  
> > +        os->ctx = ctx = avformat_alloc_context();
> > +        if (!ctx)
> > +            return AVERROR(ENOMEM);
> > +
> >          ctx->oformat = av_guess_format(os->format_name, NULL, NULL);
> >          if (!ctx->oformat)
> >              return AVERROR_MUXER_NOT_FOUND;
> > -        os->ctx = ctx;
> >          ctx->interrupt_callback    = s->interrupt_callback;
> >          ctx->opaque                = s->opaque;
> >          ctx->io_close              = s->io_close;
> LGTM

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index b84736881f..dab7010179 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -1225,10 +1225,6 @@  static int dash_init(AVFormatContext *s)
         dict_copy_entry(&as->metadata, s->streams[i]->metadata, "language");
         dict_copy_entry(&as->metadata, s->streams[i]->metadata, "role");
 
-        ctx = avformat_alloc_context();
-        if (!ctx)
-            return AVERROR(ENOMEM);
-
         if (c->init_seg_name) {
             os->init_seg_name = av_strireplace(c->init_seg_name, "$ext$", os->extension_name);
             if (!os->init_seg_name)
@@ -1261,10 +1257,13 @@  static int dash_init(AVFormatContext *s)
             }
         }
 
+        os->ctx = ctx = avformat_alloc_context();
+        if (!ctx)
+            return AVERROR(ENOMEM);
+
         ctx->oformat = av_guess_format(os->format_name, NULL, NULL);
         if (!ctx->oformat)
             return AVERROR_MUXER_NOT_FOUND;
-        os->ctx = ctx;
         ctx->interrupt_callback    = s->interrupt_callback;
         ctx->opaque                = s->opaque;
         ctx->io_close              = s->io_close;