[FFmpeg-devel] [PATCH] ffprobe: fix memleaks on errors

Michael Niedermayer michaelni at gmx.at
Wed Jan 21 13:59:01 CET 2015


On Wed, Jan 21, 2015 at 10:41:11AM +0100, Stefano Sabatini wrote:
> On date Wednesday 2015-01-21 05:47:13 +0100, Michael Niedermayer encoded:
> > Found-by: Andreas Cadhalpun <andreas.cadhalpun at googlemail.com>
> > Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> > ---
> >  ffprobe.c |   19 ++++++++++++-------
> >  1 file changed, 12 insertions(+), 7 deletions(-)
> > 
> > diff --git a/ffprobe.c b/ffprobe.c
> > index faddc16..38879f1 100644
> > --- a/ffprobe.c
> > +++ b/ffprobe.c
> > @@ -2398,6 +2398,7 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
> >          print_error(filename, err);
> >          return err;
> >      }
> > +    *fmt_ctx_ptr = fmt_ctx;
> >      if (scan_all_pmts_set)
> >          av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
> >      if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
> > @@ -2409,14 +2410,17 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
> >      opts = setup_find_stream_info_opts(fmt_ctx, codec_opts);
> >      orig_nb_streams = fmt_ctx->nb_streams;
> >  
> > -    if ((err = avformat_find_stream_info(fmt_ctx, opts)) < 0) {
> > -        print_error(filename, err);
> > -        return err;
> > -    }
> > +    err = avformat_find_stream_info(fmt_ctx, opts);
> > +
> >      for (i = 0; i < orig_nb_streams; i++)
> >          av_dict_free(&opts[i]);
> >      av_freep(&opts);
> >  
> > +    if (err < 0) {
> > +        print_error(filename, err);
> > +        return err;
> > +    }
> > +
> >      av_dump_format(fmt_ctx, 0, filename, 0);
> >  
> >      /* bind a decoder to each input stream */
> > @@ -2466,7 +2470,7 @@ static void close_input_file(AVFormatContext **ctx_ptr)
> >  
> >  static int probe_file(WriterContext *wctx, const char *filename)
> >  {
> > -    AVFormatContext *fmt_ctx;
> > +    AVFormatContext *fmt_ctx = NULL;
> >      int ret, i;
> >      int section_id;
> >  
> > @@ -2475,7 +2479,7 @@ static int probe_file(WriterContext *wctx, const char *filename)
> >  
> >      ret = open_input_file(&fmt_ctx, filename);
> >      if (ret < 0)
> > -        return ret;
> > +        goto end;
> >  
> >  #define CHECK_END if (ret < 0) goto end
> >  
> > @@ -2533,7 +2537,8 @@ static int probe_file(WriterContext *wctx, const char *filename)
> >      }
> >  
> >  end:
> > -    close_input_file(&fmt_ctx);
> > +    if (fmt_ctx)
> > +        close_input_file(&fmt_ctx);
> >      av_freep(&nb_streams_frames);
> >      av_freep(&nb_streams_packets);
> >      av_freep(&selected_streams);
> > -- 
> > 1.7.9.5
> 
> LGTM, thanks.

applied

thanks

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150121/46cb839e/attachment.asc>


More information about the ffmpeg-devel mailing list