]> git.sesse.net Git - ffmpeg/commitdiff
avformat/rtspdec: fix mem leaks in connect mode if init fails
authorAndriy Gelman <andriy.gelman@gmail.com>
Mon, 12 Oct 2020 20:36:06 +0000 (16:36 -0400)
committerAndriy Gelman <andriy.gelman@gmail.com>
Sat, 21 Nov 2020 15:13:28 +0000 (10:13 -0500)
Fixes #6334

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
libavformat/rtspdec.c

index dfc84e71ba3e5d0ccc76fcd8fbacc5484ab145af..8a2abc8ee92efd5d5290adb91ff4f6073752bccc 100644 (file)
@@ -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,