[FFmpeg-devel] [PATCH] avformat/libsrt: Fix epoll fd leak

Marton Balint cus at passwd.hu
Thu Sep 3 08:57:12 EEST 2020


On Wed, 26 Aug 2020, Nicolas Sugino wrote:

> Call srt_epoll_release() to avoid fd leak on libsrt_open() error.
> ---
> libavformat/libsrt.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
> index 4025b24976..6da372081e 100644
> --- a/libavformat/libsrt.c
> +++ b/libavformat/libsrt.c
> @@ -380,10 +380,13 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
>
>     av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
>         &port, path, sizeof(path), uri);
> -    if (strcmp(proto, "srt"))
> +    if (strcmp(proto, "srt")) {
> +        srt_epoll_release(s->eid);
>         return AVERROR(EINVAL);
> +    }
>     if (port <= 0 || port >= 65536) {
>         av_log(h, AV_LOG_ERROR, "Port missing in uri\n");
> +        srt_epoll_release(s->eid);
>         return AVERROR(EINVAL);
>     }
>     p = strchr(uri, '?');
> @@ -408,6 +411,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
>         av_log(h, AV_LOG_ERROR,
>                "Failed to resolve hostname %s: %s\n",
>                hostname, gai_strerror(ret));
> +        srt_epoll_release(s->eid);
>         return AVERROR(EIO);
>     }

Move the epoll creation before the restart label instead, this way you 
will only need the next hunk.

> 
> @@ -495,6 +499,7 @@ static int libsrt_setup(URLContext *h, const char *uri, int flags)
>     if (listen_fd >= 0)
>         srt_close(listen_fd);
>     freeaddrinfo(ai);
> +    srt_epoll_release(s->eid);
>     return ret;
> }
> 
> @@ -632,10 +637,16 @@ static int libsrt_open(URLContext *h, const char *uri, int flags)
>             s->linger = strtol(buf, NULL, 10);
>         }
>     }
> -    return libsrt_setup(h, uri, flags);
> +    ret = libsrt_setup(h, uri, flags);
> +    if (ret) {
> +        goto err;
> +    }

if (ret < 0)
    goto err;

> +    return 0;
> +
> err:
>     av_freep(&s->smoother);
>     av_freep(&s->streamid);
> +    srt_cleanup();
>     return ret;
> }

There seems to be a rouge return when parsing "mode", can you fix that as 
well?

Thanks,
Marton


More information about the ffmpeg-devel mailing list