diff mbox series

[FFmpeg-devel,02/10] avformat/audiointerleave: Fix memleak

Message ID 20200331123745.6461-3-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series libavformat/mux patches
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Andreas Rheinhardt March 31, 2020, 12:37 p.m. UTC
If ff_interleave_add_packet failed, the content of the newly created
packet new_pkt would leak.

Also, it is unnecessary to zero-initialize a packet that will be put
into av_new_packet lateron as the latter already initializes the packet.
Therefore this has been removed, too.

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

Comments

Marton Balint March 31, 2020, 7:44 p.m. UTC | #1
On Tue, 31 Mar 2020, Andreas Rheinhardt wrote:

> If ff_interleave_add_packet failed, the content of the newly created
> packet new_pkt would leak.
>
> Also, it is unnecessary to zero-initialize a packet that will be put
> into av_new_packet lateron as the latter already initializes the packet.
> Therefore this has been removed, too.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> libavformat/audiointerleave.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
> index 2e83031bd6..f10c83d7c9 100644
> --- a/libavformat/audiointerleave.c
> +++ b/libavformat/audiointerleave.c
> @@ -134,10 +134,12 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt
>     for (i = 0; i < s->nb_streams; i++) {
>         AVStream *st = s->streams[i];
>         if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
> -            AVPacket new_pkt = { 0 };
> +            AVPacket new_pkt;
>             while ((ret = interleave_new_audio_packet(s, &new_pkt, i, flush)) > 0) {
> -                if ((ret = ff_interleave_add_packet(s, &new_pkt, compare_ts)) < 0)
> +                if ((ret = ff_interleave_add_packet(s, &new_pkt, compare_ts)) < 0) {
> +                    av_packet_unref(&new_pkt);
>                     return ret;
> +                }
>             }
>             if (ret < 0)
>                 return ret;

LGTM, thanks.

Marton
diff mbox series

Patch

diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
index 2e83031bd6..f10c83d7c9 100644
--- a/libavformat/audiointerleave.c
+++ b/libavformat/audiointerleave.c
@@ -134,10 +134,12 @@  int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
         if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
-            AVPacket new_pkt = { 0 };
+            AVPacket new_pkt;
             while ((ret = interleave_new_audio_packet(s, &new_pkt, i, flush)) > 0) {
-                if ((ret = ff_interleave_add_packet(s, &new_pkt, compare_ts)) < 0)
+                if ((ret = ff_interleave_add_packet(s, &new_pkt, compare_ts)) < 0) {
+                    av_packet_unref(&new_pkt);
                     return ret;
+                }
             }
             if (ret < 0)
                 return ret;