Skip to content

Allow using fast destruction path when ASAN is in use #18835

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

danog
Copy link
Contributor

@danog danog commented Jun 11, 2025

Disabling the fast path when a custom allocator is in use hid the #18833 issue, and made it super hard to debug, this re-enables it if php is compiled with asan.

@danog
Copy link
Contributor Author

danog commented Jun 11, 2025

Ping @nielsdos

@nielsdos
Copy link
Member

By design, fast shutdown does not explicitly free all request data but defers that to ZendMM. If ZendMM is not used, but you use fast shutdown, then you get real leaks.
Therefore, your patch will report leaks with ASAN in non-debug builds.

@nielsdos
Copy link
Member

A compromise could be to make it opt-in when __SANITIZE_ADDRESS__ is set. For example, you could have an environment variable similar to USE_ZEND_ALLOC, e.g. ZEND_FORCE_FAST_SHUTDOWN. Then you check if that environment variable is set along with !EG(full_tables_cleanup) probably.

Comment on lines 441 to 444
#elif defined(__SANITIZE_ADDRESS__)
bool fast_shutdown = !EG(full_tables_cleanup);
#else
bool fast_shutdown = is_zend_mm() && !EG(full_tables_cleanup);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast_shutdown relays on Zend MM that frees the whole request heap at once. It doesn't make sense without it and will cause memory leaks.

@danog
Copy link
Contributor Author

danog commented Jun 16, 2025

Makes sense, added a ZEND_FORCE_FAST_SHUTDOWN envvar conditional: leak detection must be disabled when using this option, i.e.

ASAN_OPTIONS=detect_leaks=0 USE_ZEND_ALLOC=0 ZEND_FORCE_FAST_SHUTDOWN=1 php a.php

Detects #18833 without emitting redundant leak issues.

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