diff mbox

[FFmpeg-devel,2/3] avformat/aiffenc: Fix potential memleak upon failure

Message ID 20191002040412.821-2-andreas.rheinhardt@gmail.com
State Accepted
Commit c694fc5759719de577fd0751103e20b6ce902a8f
Headers show

Commit Message

Andreas Rheinhardt Oct. 2, 2019, 4:04 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/aiffenc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Matthieu Bouron Oct. 2, 2019, 7:10 a.m. UTC | #1
On Wed, Oct 02, 2019 at 06:04:11AM +0200, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/aiffenc.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c
> index dd8b8c3d01..0b837cd264 100644
> --- a/libavformat/aiffenc.c
> +++ b/libavformat/aiffenc.c
> @@ -235,7 +235,7 @@ static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt)
>  
>  static int aiff_write_trailer(AVFormatContext *s)
>  {
> -    int ret;
> +    int ret = 0;
>      AVIOContext *pb = s->pb;
>      AIFFOutputContext *aiff = s->priv_data;
>      AVCodecParameters *par = s->streams[aiff->audio_stream_idx]->codecpar;
> @@ -263,7 +263,7 @@ static int aiff_write_trailer(AVFormatContext *s)
>          /* Write ID3 tags */
>          if (aiff->write_id3v2)
>              if ((ret = put_id3v2_tags(s, aiff)) < 0)
> -                return ret;
> +                goto free;
>  
>          /* File length */
>          file_size = avio_tell(pb);
> @@ -273,9 +273,10 @@ static int aiff_write_trailer(AVFormatContext *s)
>          avio_flush(pb);
>      }
>  
> +free:
>      ff_packet_list_free(&aiff->pict_list, &aiff->pict_list_end);
>  
> -    return 0;
> +    return ret;
>  }
>  
>  #define OFFSET(x) offsetof(AIFFOutputContext, x)
> -- 
> 2.21.0

LGTM.
Michael Niedermayer Oct. 3, 2019, 7:04 p.m. UTC | #2
On Wed, Oct 02, 2019 at 09:10:18AM +0200, Matthieu Bouron wrote:
> On Wed, Oct 02, 2019 at 06:04:11AM +0200, Andreas Rheinhardt wrote:
> > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> > ---
> >  libavformat/aiffenc.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c
> > index dd8b8c3d01..0b837cd264 100644
> > --- a/libavformat/aiffenc.c
> > +++ b/libavformat/aiffenc.c
> > @@ -235,7 +235,7 @@ static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt)
> >  
> >  static int aiff_write_trailer(AVFormatContext *s)
> >  {
> > -    int ret;
> > +    int ret = 0;
> >      AVIOContext *pb = s->pb;
> >      AIFFOutputContext *aiff = s->priv_data;
> >      AVCodecParameters *par = s->streams[aiff->audio_stream_idx]->codecpar;
> > @@ -263,7 +263,7 @@ static int aiff_write_trailer(AVFormatContext *s)
> >          /* Write ID3 tags */
> >          if (aiff->write_id3v2)
> >              if ((ret = put_id3v2_tags(s, aiff)) < 0)
> > -                return ret;
> > +                goto free;
> >  
> >          /* File length */
> >          file_size = avio_tell(pb);
> > @@ -273,9 +273,10 @@ static int aiff_write_trailer(AVFormatContext *s)
> >          avio_flush(pb);
> >      }
> >  
> > +free:
> >      ff_packet_list_free(&aiff->pict_list, &aiff->pict_list_end);
> >  
> > -    return 0;
> > +    return ret;
> >  }
> >  
> >  #define OFFSET(x) offsetof(AIFFOutputContext, x)
> > -- 
> > 2.21.0
> 
> LGTM.

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c
index dd8b8c3d01..0b837cd264 100644
--- a/libavformat/aiffenc.c
+++ b/libavformat/aiffenc.c
@@ -235,7 +235,7 @@  static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt)
 
 static int aiff_write_trailer(AVFormatContext *s)
 {
-    int ret;
+    int ret = 0;
     AVIOContext *pb = s->pb;
     AIFFOutputContext *aiff = s->priv_data;
     AVCodecParameters *par = s->streams[aiff->audio_stream_idx]->codecpar;
@@ -263,7 +263,7 @@  static int aiff_write_trailer(AVFormatContext *s)
         /* Write ID3 tags */
         if (aiff->write_id3v2)
             if ((ret = put_id3v2_tags(s, aiff)) < 0)
-                return ret;
+                goto free;
 
         /* File length */
         file_size = avio_tell(pb);
@@ -273,9 +273,10 @@  static int aiff_write_trailer(AVFormatContext *s)
         avio_flush(pb);
     }
 
+free:
     ff_packet_list_free(&aiff->pict_list, &aiff->pict_list_end);
 
-    return 0;
+    return ret;
 }
 
 #define OFFSET(x) offsetof(AIFFOutputContext, x)