Skip to content

mod_ldap: Fix a memory leak in util_ald_create_caches() (PR 70319) - #1048

Open
arturobernalg wants to merge 1 commit into
apache:trunkfrom
arturobernalg:fix/bz70319-ldap-cache-leak
Open

arturobernalg wants to merge 1 commit into
apache:trunkfrom
arturobernalg:fix/bz70319-ldap-cache-leak

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

util_ald_create_caches() creates the search, compare and DN-compare caches for a URL and then inserts a node referring to them into the shared URL cache. When that insert returns NULL because the URL cache is full and the purge freed nothing (AH01323), the three freshly-created caches were never referenced anywhere and leaked.

Capture the insert's result and destroy the three caches when it is NULL, same as the existing cleanup path for when one of them fails to allocate in the first place.

Reproduced on a real server with an ASan build (static mod_ldap and mod_authnz_ldap, per the report): LeakSanitizer reports 13968 bytes leaked for the exact repro in the Bugzilla report; after this fix, zero leaks. Added test/modules/ldap/test_001_cache_leak.py, which measures the RSS growth of one pinned worker process over repeated alternating requests to two AuthLDAPURLs with LDAPCacheEntries 1; fails on trunk, passes with this fix.

PR: https://bz.apache.org/bugzilla/show_bug.cgi?id=70319


[x] This PR does not report or address a security vulnerability (see SECURITY.md).
[x] Code follows the httpd style guide.
[x] New log messages: N/A, no new log messages added.
[x] changes-entries/70319.txt is included.
[x] Test cases based on pyhttpd are included: test/modules/ldap/, verified locally with make check-pytest PYTEST_DIRS=test/modules/ldap.

util_ald_create_caches() creates the search, compare and DN-compare
caches for a URL and then inserts a node referring to them into the
shared URL cache. When that insert returns NULL because the URL
cache is full and the purge freed nothing (AH01323), the three
freshly-created caches were never referenced anywhere and leaked.

Capture the insert's result and destroy the three caches when it is
NULL, same as the existing cleanup path for when one of them fails
to allocate in the first place.

Reproduced on a real server with an ASan build (static mod_ldap and
mod_authnz_ldap, per the report): LeakSanitizer reports 13968 bytes
leaked for the exact repro in the Bugzilla report; after this fix,
zero leaks. Added test/modules/ldap/test_001_cache_leak.py, which
measures the RSS growth of one pinned worker process over repeated
alternating requests to two AuthLDAPURLs with LDAPCacheEntries 1;
fails on trunk, passes with this fix. The test is skipped off Linux
(it reads /proc) and under AddressSanitizer, whose own allocations
dwarf the leak in RSS.

PR: https://bz.apache.org/bugzilla/show_bug.cgi?id=70319
@arturobernalg
arturobernalg force-pushed the fix/bz70319-ldap-cache-leak branch from 69eb12a to 97f63f4 Compare November 17, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant