|
1 | 1 | --TEST-- |
2 | | -GH-22176 (Memory leak when a ZipArchive cancel/progress callback bails out in the shutdown destructor) |
| 2 | +GH-22176 (Memory leak when a ZipArchive cancel callback bails out in the shutdown destructor) |
3 | 3 | --EXTENSIONS-- |
4 | 4 | zip |
5 | 5 | --SKIPIF-- |
6 | 6 | <?php |
7 | 7 | if (!method_exists('ZipArchive', 'registerCancelCallback')) die('skip libzip too old'); |
8 | | -if (!method_exists('ZipArchive', 'registerProgressCallback')) die('skip libzip too old'); |
9 | 8 | ?> |
10 | 9 | --FILE-- |
11 | 10 | <?php |
12 | | -$dir = __DIR__ . '/'; |
13 | | - |
14 | | -$cancel = new ZipArchive; |
15 | | -$cancel->open($dir . 'gh22176_cancel.zip', ZipArchive::CREATE); |
16 | | -$cancel->registerCancelCallback(function () { |
| 11 | +$zip = new ZipArchive; |
| 12 | +$zip->open(__DIR__ . '/gh22176_cancel.zip', ZipArchive::CREATE); |
| 13 | +$zip->registerCancelCallback(function () { |
17 | 14 | throw new \Exception('cancel boom'); |
18 | 15 | }); |
19 | | -$cancel->addFromString('test', 'test'); |
20 | | - |
21 | | -$progress = new ZipArchive; |
22 | | -$progress->open($dir . 'gh22176_progress.zip', ZipArchive::CREATE); |
23 | | -$progress->registerProgressCallback(0.5, function ($r) { |
24 | | - throw new \Exception('progress boom'); |
25 | | -}); |
26 | | -$progress->addFromString('test', 'test'); |
27 | | - |
| 16 | +$zip->addFromString('test', 'test'); |
28 | 17 | echo "done\n"; |
29 | | -// Both archives are flushed and the objects destroyed during request |
30 | | -// shutdown; the thrown exceptions bail out through libzip's zip_close() |
31 | | -// without leaking its internal state. |
| 18 | +// The archive is flushed and the object destroyed during request shutdown; |
| 19 | +// the thrown exception bails out through libzip's zip_close() without leaking |
| 20 | +// its internal state, and the bailout resumes once libzip has unwound. |
32 | 21 | ?> |
33 | 22 | --CLEAN-- |
34 | 23 | <?php |
35 | 24 | @unlink(__DIR__ . '/gh22176_cancel.zip'); |
36 | | -@unlink(__DIR__ . '/gh22176_progress.zip'); |
37 | 25 | ?> |
38 | 26 | --EXPECTF-- |
39 | 27 | done |
40 | 28 |
|
41 | | -Fatal error: Uncaught Exception: progress boom in %s:%d |
42 | | -Stack trace: |
43 | | -#0 [internal function]: {closure:%s:%d}(0.0) |
44 | | -#1 {main} |
45 | | - thrown in %s on line %d |
46 | | - |
47 | | -Fatal error: Uncaught Exception: progress boom in %s:%d |
48 | | -Stack trace: |
49 | | -#0 [internal function]: {closure:%s:%d}(1.0) |
50 | | -#1 {main} |
51 | | - thrown in %s on line %d |
52 | | - |
53 | 29 | Fatal error: Uncaught Exception: cancel boom in %s:%d |
54 | 30 | Stack trace: |
55 | 31 | #0 [internal function]: {closure:%s:%d}() |
56 | 32 | #1 {main} |
57 | 33 | thrown in %s on line %d |
58 | | - |
59 | | -Warning: PHP Request Shutdown: Cannot destroy the zip context: %s in Unknown on line 0 |
0 commit comments