Skip to content

Commit

Permalink
avformat/tcp: TCP Protocol: fix descriptor leak on listen and interrupt
Browse files Browse the repository at this point in the history
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@googlemail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
  • Loading branch information
h4tr3d authored and michaelni committed Sep 11, 2015
1 parent f600381 commit 6a8d58d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libavformat/tcp.c
Expand Up @@ -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) {
Expand Down

0 comments on commit 6a8d58d

Please sign in to comment.