[FFmpeg-devel,v1,8/8] avformat/sapdec: check av_strdup() return value and fix memleak

Submitted by Steven Liu on Oct. 10, 2019, 3:40 a.m.

Details

Message ID 20191010034011.1205-8-lq@chinaffmpeg.org
State New
Headers show

Commit Message

Steven Liu Oct. 10, 2019, 3:40 a.m.
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavformat/sapdec.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Zhao Zhili Oct. 10, 2019, 5:13 a.m.
> On Oct 10, 2019, at 11:40 AM, Steven Liu <lq@chinaffmpeg.org> wrote:
> 
> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> ---
> libavformat/sapdec.c | 5 +++++
> 1 file changed, 5 insertions(+)
> 
> diff --git a/libavformat/sapdec.c b/libavformat/sapdec.c
> index eddeddeaea..4cce700b40 100644
> --- a/libavformat/sapdec.c
> +++ b/libavformat/sapdec.c
> @@ -142,6 +142,10 @@ static int sap_read_header(AVFormatContext *s)
>         }
> 
>         sap->sdp = av_strdup(&recvbuf[pos]);
> +        if (!sap->sdp) {
> +            ret = AVERROR(ENOMEM);
> +            goto fail;
> +        }
>         break;
>     }
> 
> @@ -183,6 +187,7 @@ static int sap_read_header(AVFormatContext *s)
>     return 0;
> 
> fail:
> +    av_freep(&sap->sdp);

It should be freed by sap_read_close.

>     sap_read_close(s);
>     return ret;
> }
> -- 
> 2.15.1
> 
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

Patch hide | download patch | download mbox

diff --git a/libavformat/sapdec.c b/libavformat/sapdec.c
index eddeddeaea..4cce700b40 100644
--- a/libavformat/sapdec.c
+++ b/libavformat/sapdec.c
@@ -142,6 +142,10 @@  static int sap_read_header(AVFormatContext *s)
         }
 
         sap->sdp = av_strdup(&recvbuf[pos]);
+        if (!sap->sdp) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
         break;
     }
 
@@ -183,6 +187,7 @@  static int sap_read_header(AVFormatContext *s)
     return 0;
 
 fail:
+    av_freep(&sap->sdp);
     sap_read_close(s);
     return ret;
 }