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;
}
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 = {