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 if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
7--FILE--
8<?php
9
10$ch = curl_init(getenv('PHP_CURL_HTTP_REMOTE_SERVER'));
11
12$temp_file = dirname(__FILE__) . '/curl_file_deleted_before_curl_close.tmp';
13if (file_exists($temp_file)) {
14	unlink($temp_file); // file should not exist before test
15}
16
17$handle = fopen($temp_file, 'w');
18
19curl_setopt($ch, CURLOPT_STDERR, $handle);
20curl_setopt($ch, CURLOPT_VERBOSE, 1);
21curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
22
23curl_exec($ch);
24
25fclose($handle); // causes glibc memory error
26
27//unlink($temp_file); // uncomment to test segfault (file not found on iowrite.c)
28
29curl_close($ch);
30echo "Closed correctly\n";
31?>
32--CLEAN--
33<?php
34unlink(dirname(__FILE__) . '/curl_file_deleted_before_curl_close.tmp');
35?>
36--EXPECTF--
37* Closing connection #%d
38Closed correctly
39