@@ -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),
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(-)