summaryrefslogtreecommitdiff
path: root/ext/standard/php_fopen_wrapper.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/php_fopen_wrapper.c')
-rw-r--r--ext/standard/php_fopen_wrapper.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c
index 87457e60e5..1d1810b49f 100644
--- a/ext/standard/php_fopen_wrapper.c
+++ b/ext/standard/php_fopen_wrapper.c
@@ -124,6 +124,7 @@ php_stream_ops php_stream_input_ops = {
php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
{
int fd = -1;
+ php_stream *stream = NULL;
if (!strncasecmp(path, "php://", 6))
path += 6;
@@ -145,9 +146,13 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
}
if (fd != -1) {
- return php_stream_fopen_from_fd(fd, mode, NULL);
+ int nfd = dup(fd);
+
+ stream = php_stream_fopen_from_fd(nfd, mode, NULL);
+
+ if (!stream) close(nfd);
}
- return NULL;
+ return stream;
}
static php_stream_wrapper_ops php_stdio_wops = {