[php-src] Issue #15421: Memory leak in PDO with large number of parameters

From: Date: Thu, 15 Aug 2024 09:54:54 +0000
Subject: [php-src] Issue #15421: Memory leak in PDO with large number of parameters
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-247500@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/15421 Author: BOPOH ### Description The following code: ```php <?php declare(strict_types = 1); $filters = [ range($startIndex = 1000, $startIndex + ($step = 1000) * 1), range($startIndex, $startIndex + $step * 2), range($startIndex, $startIndex + $step * 3), range($startIndex, $startIndex + $step * 4), range($startIndex = 10000, $startIndex + ($step = 10000) * 5), range($startIndex, $startIndex + $step * 6), range($startIndex, $startIndex + $step * 7), range($startIndex, $startIndex + $step * 8), range($startIndex = 100000, $startIndex + ($step = 1000) * 1), range($startIndex, $startIndex + $step * 2), range($startIndex, $startIndex + $step * 3), range($startIndex, $startIndex + $step * 4), range($startIndex = 110000, $startIndex + ($step = 10000) * 5), range($startIndex, $startIndex + $step * 6), range($startIndex, $startIndex + $step * 7), range($startIndex, $startIndex + $step * 8), ]; unset($startIndex); unset($step); echo memory_get_usage(true) . " before\n"; foreach ($filters as $i => $ids) { if ($i % 4 === 0) { echo "\n"; } $in = str_repeat('?,', count($ids) - 1) . '?'; $pdo = new \PDO($dsn = 'mysql:...', $user = 'root', $password = 'root'); $stmt = $pdo->prepare("SELECT 1 AS id HAVING id IN ($in)"); $stmt->execute($ids); $result = $stmt->fetchAll(); $stmt->closeCursor(); unset($result); unset($stmt); unset($pdo); unset($in); unset($ids); gc_collect_cycles(); echo memory_get_usage(true) . " $i\n"; } echo "\n" . memory_get_usage(true) . " after\n"; ``` Resulted in this output: <table> <tr> <th>PHP8.1</th> <th>PHP8.2</th> <th>PHP8.3</th> </tr> <tr> <td> ``` 27295744 before 27295744 0 27295744 1 29392896 2 29392896 3 37781504 4 39878656 5 41975808 6 41975808 7 41975808 8 41975808 9 41975808 10 41975808 11 44072960 12 44072960 13 46170112 14 46170112 15 46170112 after ``` </td> <td> ``` 16793600 before 16793600 0 16793600 1 16793600 2 16793600 3 25182208 4 27279360 5 27279360 6 29376512 7 29376512 8 29376512 9 29376512 10 29376512 11 31473664 12 31473664 13 31473664 14 33570816 15 33570816 after ``` </td> <td> ``` 16793600 before 16793600 0 16793600 1 16793600 2 16793600 3 25182208 4 27279360 5 27279360 6 29376512 7 29376512 8 29376512 9 29376512 10 29376512 11 31473664 12 33570816 13 33570816 14 33570816 15 33570816 after ``` </td> </tr> </table> But I expected this output instead: ``` 16793600 before 16793600 0 16793600 1 16793600 2 16793600 3 16793600 4 16793600 5 16793600 6 16793600 7 16793600 8 16793600 9 16793600 10 16793600 11 16793600 12 16793600 13 16793600 14 16793600 15 16793600 after ``` ### PHP Version PHP8.1.29 PHP8.2.22 PHP8.3.9 ### Operating System Linux Mint 20.3

« previous php.bugs (#247500) next »