Skip to content

Commit 27852f2

Browse files
Anders Nystromlu-zero
authored andcommitted
libavformat: Handle error return from ff_listen_bind
Handle error return from ff_listen_bind without leaking file descriptors. Signed-off-by: Anders Nystrom <[email protected]> Signed-off-by: Luca Barbato <[email protected]>
1 parent 0266988 commit 27852f2

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

libavformat/tcp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
114114
}
115115

116116
if (s->listen) {
117-
if ((fd = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
118-
s->listen_timeout, h)) < 0) {
119-
ret = fd;
117+
if ((ret = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
118+
s->listen_timeout, h)) < 0) {
120119
goto fail1;
121120
}
121+
fd = ret;
122122
} else {
123123
if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
124124
s->timeout, h, !!cur_ai->ai_next)) < 0) {

libavformat/unix.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,11 @@ static int unix_open(URLContext *h, const char *filename, int flags)
7575
return ff_neterrno();
7676

7777
if (s->listen) {
78-
fd = ff_listen_bind(fd, (struct sockaddr *)&s->addr,
79-
sizeof(s->addr), s->timeout, h);
80-
if (fd < 0) {
81-
ret = fd;
78+
ret = ff_listen_bind(fd, (struct sockaddr *)&s->addr,
79+
sizeof(s->addr), s->timeout, h);
80+
if (ret < 0)
8281
goto fail;
83-
}
82+
fd = ret;
8483
} else {
8584
ret = ff_listen_connect(fd, (struct sockaddr *)&s->addr,
8685
sizeof(s->addr), s->timeout, h, 0);

0 commit comments

Comments
 (0)