diff mbox series

[FFmpeg-devel,v2,2/3] avformat/file: dup file descriptor for pipe protocol

Message ID tencent_26AE3B4DC145B5D86AB600F16A527D0AAE0A@qq.com
State New
Headers show
Series [FFmpeg-devel,v2,1/3] avformat/file: add fd protocol | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Zhao Zhili Dec. 11, 2022, 3:17 p.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

This can fix read/write error when user close the file descriptor
earlier. Now user can close the file descriptor earlier to avoid
file descriptor leak. So it's safer in both way.
---
 libavformat/file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavformat/file.c b/libavformat/file.c
index b8725c1f48..f7ebd52433 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -401,7 +401,9 @@  static int pipe_open(URLContext *h, const char *filename, int flags)
 #if HAVE_SETMODE
     setmode(fd, O_BINARY);
 #endif
-    c->fd = fd;
+    c->fd = dup(fd);
+    if (c->fd < 0)
+        return AVERROR(errno);
     h->is_streamed = 1;
     return 0;
 }
@@ -411,6 +413,7 @@  const URLProtocol ff_pipe_protocol = {
     .url_open            = pipe_open,
     .url_read            = file_read,
     .url_write           = file_write,
+    .url_close           = file_close,
     .url_get_file_handle = file_get_handle,
     .url_check           = file_check,
     .priv_data_size      = sizeof(FileContext),