You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
require of a unit that returns a value: the array is released once per call but retained once, and realpath's buffer leaks #559
require / include of a compile unit that ends in return [...] has two memory bugs. Both are fixed in #555; this issue records them so the gap is visible on main.
1. Crash: the returned value is released once per require, but the unit slot holds a single count
// a.php<?phpreturn ['name' => 'conf', 'n' => 3];
// main.php<?php$x1 = require__DIR__ . '/a.php';
$x2 = require__DIR__ . '/a.php'; // second require of the same unitvar_dump($x1['n'], $x2['n']);
Compile the directory. With one require the program is fine. With two or more, the same array is released twice at exit: __mir_array_release_cell reads freed memory. macOS libgmalloc shows it (DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib ./bin, exit 139); on Linux the default allocator crashes (CI: require_const_fold, rc=139). Cause: __mir_incl_resolve returns the slot's word without a retain, while every consumer treats a call result as an owned +1.
2. Leak: every require leaks a realpath buffer
The include resolver calls realpath(path, NULL), which mallocs the answer, and never frees it. About 1 KB per call in a loop; 300,000 calls of function f() { $x = require __DIR__ . '/a.php'; ... } grew memory by 308 MB. Matters for a long-running server that requires data files per request.
Fix
In #555: __mir_cell_retain on the slot-hit arm and free(realpath) after the resolve chain; case require_value_ownership (double require, require as argument / statement / element, flat memory over 100k calls).
Activity