diff mbox

[FFmpeg-devel,V1,3/4] lavf/avidec: fix memory leak in error handling path

Message ID 1568115568-14548-3-git-send-email-mypopydev@gmail.com
State Accepted
Commit 3740bdee77ae1810162fc215172f432fcee2d0f0
Headers show

Commit Message

Jun Zhao Sept. 10, 2019, 11:39 a.m. UTC
From: Jun Zhao <barryjzhao@tencent.com>

free the value in error handling path to avoid the memory leak.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
---
 libavformat/avidec.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

Comments

Michael Niedermayer Sept. 10, 2019, 3:14 p.m. UTC | #1
On Tue, Sep 10, 2019 at 07:39:27PM +0800, Jun Zhao wrote:
> From: Jun Zhao <barryjzhao@tencent.com>
> 
> free the value in error handling path to avoid the memory leak.
> 
> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> ---
>  libavformat/avidec.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/libavformat/avidec.c b/libavformat/avidec.c
> index df78925..e3cd844 100644
> --- a/libavformat/avidec.c
> +++ b/libavformat/avidec.c
> @@ -306,8 +306,10 @@ static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag,
>      value = av_malloc(size + 1);
>      if (!value)
>          return AVERROR(ENOMEM);
> -    if (avio_read(pb, value, size) != size)
> +    if (avio_read(pb, value, size) != size) {
> +        av_freep(&value);
>          return AVERROR_INVALIDDATA;
> +    }
>      value[size] = 0;

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index df78925..e3cd844 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -306,8 +306,10 @@  static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag,
     value = av_malloc(size + 1);
     if (!value)
         return AVERROR(ENOMEM);
-    if (avio_read(pb, value, size) != size)
+    if (avio_read(pb, value, size) != size) {
+        av_freep(&value);
         return AVERROR_INVALIDDATA;
+    }
     value[size] = 0;
 
     AV_WL32(key, tag);