diff mbox series

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

Message ID 20200826040257.9709-1-nsugino@3way.com.ar
State New
Headers show
Series [FFmpeg-devel] avformat/libsrt: Fix epoll fd leak
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Nicolas Sugino Aug. 26, 2020, 4:02 a.m. UTC
Call srt_epoll_release() to avoid fd leak on libsrt_open() error.
---
 libavformat/libsrt.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Marton Balint Sept. 3, 2020, 5:57 a.m. UTC | #1
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
diff mbox series

Patch

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);
     }
 
@@ -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;
+    }
+    return 0;
+
 err:
     av_freep(&s->smoother);
     av_freep(&s->streamid);
+    srt_cleanup();
     return ret;
 }