[FFmpeg-devel,v1,4/8] avformat/libsrt: 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-4-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/libsrt.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Zhao Zhili Oct. 10, 2019, 5:03 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/libsrt.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
> index b5568089fa..91e8c4b55b 100644
> --- a/libavformat/libsrt.c
> +++ b/libavformat/libsrt.c
> @@ -478,6 +478,7 @@ static int libsrt_open(URLContext *h, const char *uri, int flags)
>    SRTContext *s = h->priv_data;
>    const char * p;
>    char buf[256];
> +    int ret = 0;
> 
>    if (srt_startup() < 0) {
>        return AVERROR_UNKNOWN;
> @@ -564,10 +565,18 @@ static int libsrt_open(URLContext *h, const char *uri, int flags)
>        if (av_find_info_tag(buf, sizeof(buf), "streamid", p)) {
>            av_freep(&s->streamid);
>            s->streamid = av_strdup(buf);
> +            if (!s->streamid) {
> +                ret = AVERROR(ENOMEM);
> +                goto err;
> +            }
>        }
>        if (av_find_info_tag(buf, sizeof(buf), "smoother", p)) {
>            av_freep(&s->smoother);
>            s->smoother = av_strdup(buf);
> +            if(!s->smoother) {
> +                ret = AVERROR(ENOMEM);
> +                goto err;
> +            }
>        }
>        if (av_find_info_tag(buf, sizeof(buf), "messageapi", p)) {
>            s->messageapi = strtol(buf, NULL, 10);
> @@ -578,11 +587,15 @@ static int libsrt_open(URLContext *h, const char *uri, int flags)
>            } else if (!strcmp(buf, "file")) {
>                s->transtype = SRTT_FILE;
>            } else {
> -                return AVERROR(EINVAL);
> +                ret = AVERROR(EINVAL);
> +                goto err;
>            }
>        }
>    }
>    return libsrt_setup(h, uri, flags);
> +err:
> +    av_freep(&s->smoother);
> +    av_freep(&s->streamid);
> }

Miss return.

> 
> static int libsrt_read(URLContext *h, uint8_t *buf, int size)
> -- 
> 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/libsrt.c b/libavformat/libsrt.c
index b5568089fa..91e8c4b55b 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -478,6 +478,7 @@  static int libsrt_open(URLContext *h, const char *uri, int flags)
     SRTContext *s = h->priv_data;
     const char * p;
     char buf[256];
+    int ret = 0;
 
     if (srt_startup() < 0) {
         return AVERROR_UNKNOWN;
@@ -564,10 +565,18 @@  static int libsrt_open(URLContext *h, const char *uri, int flags)
         if (av_find_info_tag(buf, sizeof(buf), "streamid", p)) {
             av_freep(&s->streamid);
             s->streamid = av_strdup(buf);
+            if (!s->streamid) {
+                ret = AVERROR(ENOMEM);
+                goto err;
+            }
         }
         if (av_find_info_tag(buf, sizeof(buf), "smoother", p)) {
             av_freep(&s->smoother);
             s->smoother = av_strdup(buf);
+            if(!s->smoother) {
+                ret = AVERROR(ENOMEM);
+                goto err;
+            }
         }
         if (av_find_info_tag(buf, sizeof(buf), "messageapi", p)) {
             s->messageapi = strtol(buf, NULL, 10);
@@ -578,11 +587,15 @@  static int libsrt_open(URLContext *h, const char *uri, int flags)
             } else if (!strcmp(buf, "file")) {
                 s->transtype = SRTT_FILE;
             } else {
-                return AVERROR(EINVAL);
+                ret = AVERROR(EINVAL);
+                goto err;
             }
         }
     }
     return libsrt_setup(h, uri, flags);
+err:
+    av_freep(&s->smoother);
+    av_freep(&s->streamid);
 }
 
 static int libsrt_read(URLContext *h, uint8_t *buf, int size)