[FFmpeg-cvslog] avformat/tcp: TCP Protocol: fix descriptor leak on listen and interrupt

Alexander S. Drozdov git at videolan.org
Fri Sep 11 22:01:47 CEST 2015


ffmpeg | branch: master | Alexander S. Drozdov <adrozdoff at gmail.com> | Fri Sep 11 16:31:44 2015 +1000| [6a8d58d69309d27402714caeaf92a7270e0f2a84] | committer: Michael Niedermayer

avformat/tcp: TCP Protocol: fix descriptor leak on listen and interrupt

If we try to listen on TCP port and ff_listen() fails on
interrupt callback socket (bind) descriptor overwrites and
does not closed at all.

As a result, we can't rebind to the same port.

Reviewed-by: Stephan Holljes <klaxa1337 at googlemail.com>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6a8d58d69309d27402714caeaf92a7270e0f2a84
---

 libavformat/tcp.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index bee349e..e02c64b 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -132,11 +132,11 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
             goto fail1;
     } else if (s->listen == 1) {
         // single client
-        if ((fd = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
-                                 s->listen_timeout, h)) < 0) {
-            ret = fd;
+        if ((ret = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
+                                  s->listen_timeout, h)) < 0)
             goto fail1;
-        }
+        // Socket descriptor already closed here. Safe to overwrite to client one.
+        fd = ret;
     } else {
         if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
                                      s->open_timeout / 1000, h, !!cur_ai->ai_next)) < 0) {



More information about the ffmpeg-cvslog mailing list