Skip to content

Commit a9c04ae

Browse files
committed
Always delete tempfile created by ftruncate test.
The ftruncate() test will fill up the disk when the disk has less than 2GB of space left, on some systems. I think it expands the file to less than 2GB, then returns an error code, and the file remains at the larger size. Because the disk is full, the `--CLEAN--` script can't be saved to `ftruncate_bug76422.clean.php` to be executed, and the cleanup can't be run. Subsequent tests also fail to run. Closes GH-5043
1 parent 349a286 commit a9c04ae

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ext/standard/tests/file/ftruncate_bug76422.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,26 @@ $truncate_offset = 2 * 1024 * 1024 * 1024;
2323
$ftruncate_result = ftruncate($file_handle, $truncate_offset);
2424
if (false === $ftruncate_result) {
2525
var_dump(true);
26+
fclose($file_handle);
27+
unlink($fn);
2628
return;
2729
}
2830

2931
$truncate_offset = 4 * 1024 * 1024 * 1024 + 1;
3032
$ftruncate_result = ftruncate($file_handle, $truncate_offset);
3133

3234
if (false === $ftruncate_result) {
35+
// NOTE: unlink() is deliberately repeated - If this test runs out of disk space attempting to reserve space for this temporary file,
36+
// then the --CLEAN-- script can't be run (if we don't delete the file),
37+
// because there wouldn't be any free disk space to save a new php file.
38+
fclose($file_handle);
39+
unlink($fn);
3340
die('Truncate has failed :/');
3441
}
3542

3643
fclose($file_handle);
3744
var_dump(filesize($fn) >= $truncate_offset);
45+
unlink($fn);
3846
?>
3947
--CLEAN--
4048
<?php

0 commit comments

Comments
 (0)