Skip to content

Free internal_runtime_cache on shutdown for NTS #16402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Oct 12, 2024

The internal runtime cache is never freed for NTS builds; as a stop- gap measure we disable the leak detection.


The leak is detected by the CRT debug heap (e.g. when running the ext/zend_test test suite), likely as of 25d7616. I don't know whether that change introduced, or merely exhibited the issue.

@bwoebi
Copy link
Member

bwoebi commented Oct 20, 2024

That's an oversight. In ZTS it's freed in compiler_globals_dtor, but in NTS that function isn't executed.
For NTS, compiler globals shutdown essentially happens within zend_shutdown().

That #else directive within zend_shutdown should include if (CG(internal_run_time_cache)) { pefree(CG(internal_run_time_cache), 1); CG(internal_run_time_cache) = NULL; }.
(Just marking the leak not checked obviously works, but isn't quite the point of it.)

(To be honest, it is quite confusing that there are different codepaths for NTS and ZTS. I'd say both should end up calling compiler_globals_dtor, and then you'd #ifdef ZTS the stuff you don't need in NTS there...)

As is, the `internal_runtime_cache` is only free for ZTS builds; we
also free it for NTS builds on shutdown.

Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
@cmb69 cmb69 force-pushed the cmb/internal-runtime-cache-ignore-leak branch from a4bbd68 to 25e2d9a Compare October 20, 2024 12:18
@cmb69 cmb69 requested a review from dstogov as a code owner October 20, 2024 12:18
@cmb69
Copy link
Member Author

cmb69 commented Oct 20, 2024

Thanks @bwoebi. I wasn't sure whether the current behavior is intentional; after all the memory is freed when the process terminates anyway.

To be honest, it is quite confusing that there are different codepaths for NTS and ZTS. I'd say both should end up calling compiler_globals_dtor, and then you'd #ifdef ZTS the stuff you don't need in NTS there...

Yeah, that seems to be reasonable.

@cmb69 cmb69 changed the title Disable leak detection for internal runtime cache for NTS Free internal_runtime_cache on shutdown for NTS Oct 20, 2024
@cmb69 cmb69 closed this in fd39e23 Oct 21, 2024
@cmb69 cmb69 deleted the cmb/internal-runtime-cache-ignore-leak branch October 21, 2024 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants