diff mbox series

[FFmpeg-devel,v3,3/6] avformat/rtspdec: fix mem leaks in connect mode if init fails

Message ID 20201012203609.41647-3-andriy.gelman@gmail.com
State Accepted
Commit 122fcf1f407b60baf7a0322b73798958ca6108eb
Headers show
Series [FFmpeg-devel,v3,1/6] avformat/rtspdec: add network init to listen mode | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andriy Gelman Oct. 12, 2020, 8:36 p.m. UTC
From: Andriy Gelman <andriy.gelman@gmail.com>

Fixes #6334

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
---
 libavformat/rtspdec.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Comments

Martin Storsjö Nov. 20, 2020, 8:23 a.m. UTC | #1
On Mon, 12 Oct 2020, Andriy Gelman wrote:

> From: Andriy Gelman <andriy.gelman@gmail.com>
>
> Fixes #6334
>
> Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
> ---
> libavformat/rtspdec.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
> index 5a383b5a19..7c617837ca 100644
> --- a/libavformat/rtspdec.c
> +++ b/libavformat/rtspdec.c
> @@ -735,22 +735,26 @@ static int rtsp_read_header(AVFormatContext *s)
>
>         rt->real_setup_cache = !s->nb_streams ? NULL :
>             av_mallocz_array(s->nb_streams, 2 * sizeof(*rt->real_setup_cache));
> -        if (!rt->real_setup_cache && s->nb_streams)
> -            return AVERROR(ENOMEM);
> +        if (!rt->real_setup_cache && s->nb_streams) {
> +            ret = AVERROR(ENOMEM);
> +            goto fail;
> +        }
>         rt->real_setup = rt->real_setup_cache + s->nb_streams;
>
>         if (rt->initial_pause) {
>             /* do not start immediately */
>         } else {
>             if ((ret = rtsp_read_play(s)) < 0) {
> -                ff_rtsp_close_streams(s);
> -                ff_rtsp_close_connections(s);
> -                return ret;
> +                goto fail;
>             }
>         }
>     }
>
>     return 0;
> +
> +fail:
> +    rtsp_read_close(s);
> +    return ret;
> }
> 
> int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
> -- 
> 2.28.0

Looks ok, assuming that the error codepath has been tested.

// Martin
diff mbox series

Patch

diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index 5a383b5a19..7c617837ca 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -735,22 +735,26 @@  static int rtsp_read_header(AVFormatContext *s)
 
         rt->real_setup_cache = !s->nb_streams ? NULL :
             av_mallocz_array(s->nb_streams, 2 * sizeof(*rt->real_setup_cache));
-        if (!rt->real_setup_cache && s->nb_streams)
-            return AVERROR(ENOMEM);
+        if (!rt->real_setup_cache && s->nb_streams) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
         rt->real_setup = rt->real_setup_cache + s->nb_streams;
 
         if (rt->initial_pause) {
             /* do not start immediately */
         } else {
             if ((ret = rtsp_read_play(s)) < 0) {
-                ff_rtsp_close_streams(s);
-                ff_rtsp_close_connections(s);
-                return ret;
+                goto fail;
             }
         }
     }
 
     return 0;
+
+fail:
+    rtsp_read_close(s);
+    return ret;
 }
 
 int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,