Message ID | 20200814011826.11681-1-nsugino@3way.com.ar |
---|---|
State | Accepted |
Commit | 86f5fd471d35423e3bd5c9d2bd0076b14124faee |
Headers | show |
Series | [FFmpeg-devel,v4] avformat/libsrt: Close listen fd in listener mode | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
On Thu, 13 Aug 2020, Nicolas Sugino wrote: > In listener mode the first fd is not closed when libsrt_close() is called because it is overwritten by the new accept fd. > Added the listen_fd to the context to properly close it when libsrt_close() is called. > Fixes trac ticket #8372 Thanks, applied. Regards, Marton > > Signed-off-by: Nicolas Sugino <nsugino@3way.com.ar> > --- > libavformat/libsrt.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c > index 4719ce0d4b..4025b24976 100644 > --- a/libavformat/libsrt.c > +++ b/libavformat/libsrt.c > @@ -53,6 +53,7 @@ enum SRTMode { > typedef struct SRTContext { > const AVClass *class; > int fd; > + int listen_fd; > int eid; > int64_t rw_timeout; > int64_t listen_timeout; > @@ -362,7 +363,7 @@ static int libsrt_set_options_pre(URLContext *h, int fd) > static int libsrt_setup(URLContext *h, const char *uri, int flags) > { > struct addrinfo hints = { 0 }, *ai, *cur_ai; > - int port, fd = -1; > + int port, fd = -1, listen_fd = -1; > SRTContext *s = h->priv_data; > const char *p; > char buf[256]; > @@ -439,6 +440,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags) > // multi-client > if ((ret = libsrt_listen(s->eid, fd, cur_ai->ai_addr, cur_ai->ai_addrlen, h, s->listen_timeout)) < 0) > goto fail1; > + listen_fd = fd; > fd = ret; > } else { > if (s->mode == SRT_MODE_RENDEZVOUS) { > @@ -471,6 +473,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags) > > h->is_streamed = 1; > s->fd = fd; > + s->listen_fd = listen_fd; > > freeaddrinfo(ai); > return 0; > @@ -481,12 +484,16 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags) > cur_ai = cur_ai->ai_next; > if (fd >= 0) > srt_close(fd); > + if (listen_fd >= 0) > + srt_close(listen_fd); > ret = 0; > goto restart; > } > fail1: > if (fd >= 0) > srt_close(fd); > + if (listen_fd >= 0) > + srt_close(listen_fd); > freeaddrinfo(ai); > return ret; > } > @@ -676,6 +683,9 @@ static int libsrt_close(URLContext *h) > > srt_close(s->fd); > > + if (s->listen_fd >= 0) > + srt_close(s->listen_fd); > + > srt_epoll_release(s->eid); > > srt_cleanup(); > -- > 2.17.1 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c index 4719ce0d4b..4025b24976 100644 --- a/libavformat/libsrt.c +++ b/libavformat/libsrt.c @@ -53,6 +53,7 @@ enum SRTMode { typedef struct SRTContext { const AVClass *class; int fd; + int listen_fd; int eid; int64_t rw_timeout; int64_t listen_timeout; @@ -362,7 +363,7 @@ static int libsrt_set_options_pre(URLContext *h, int fd) static int libsrt_setup(URLContext *h, const char *uri, int flags) { struct addrinfo hints = { 0 }, *ai, *cur_ai; - int port, fd = -1; + int port, fd = -1, listen_fd = -1; SRTContext *s = h->priv_data; const char *p; char buf[256]; @@ -439,6 +440,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags) // multi-client if ((ret = libsrt_listen(s->eid, fd, cur_ai->ai_addr, cur_ai->ai_addrlen, h, s->listen_timeout)) < 0) goto fail1; + listen_fd = fd; fd = ret; } else { if (s->mode == SRT_MODE_RENDEZVOUS) { @@ -471,6 +473,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags) h->is_streamed = 1; s->fd = fd; + s->listen_fd = listen_fd; freeaddrinfo(ai); return 0; @@ -481,12 +484,16 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags) cur_ai = cur_ai->ai_next; if (fd >= 0) srt_close(fd); + if (listen_fd >= 0) + srt_close(listen_fd); ret = 0; goto restart; } fail1: if (fd >= 0) srt_close(fd); + if (listen_fd >= 0) + srt_close(listen_fd); freeaddrinfo(ai); return ret; } @@ -676,6 +683,9 @@ static int libsrt_close(URLContext *h) srt_close(s->fd); + if (s->listen_fd >= 0) + srt_close(s->listen_fd); + srt_epoll_release(s->eid); srt_cleanup();
In listener mode the first fd is not closed when libsrt_close() is called because it is overwritten by the new accept fd. Added the listen_fd to the context to properly close it when libsrt_close() is called. Fixes trac ticket #8372 Signed-off-by: Nicolas Sugino <nsugino@3way.com.ar> --- libavformat/libsrt.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)