1--TEST--
2Memory corruption error if fp of just created file is closed before curl_close.
3--CREDITS--
4Alexey Shein <confik@gmail.com>
5--SKIPIF--
6<?php include 'skipif.inc'; ?>
7--FILE--
8<?php
9
10include 'server.inc';
11$host = curl_cli_server_start();
12$ch = curl_init($host);
13
14$temp_file = __DIR__ . '/curl_file_deleted_before_curl_close.tmp';
15if (file_exists($temp_file)) {
16	unlink($temp_file); // file should not exist before test
17}
18
19$handle = fopen($temp_file, 'w');
20
21curl_setopt($ch, CURLOPT_STDERR, $handle);
22curl_setopt($ch, CURLOPT_VERBOSE, 1);
23curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
24
25curl_exec($ch);
26
27fclose($handle); // causes glibc memory error
28
29//unlink($temp_file); // uncomment to test segfault (file not found on iowrite.c)
30
31curl_close($ch);
32echo "Closed correctly\n";
33?>
34--CLEAN--
35<?php
36unlink(__DIR__ . '/curl_file_deleted_before_curl_close.tmp');
37?>
38--EXPECT--
39Closed correctly
40