Skip to content

Fix memory leaks in plugins#13028

Open
bryancall wants to merge 5 commits intoapache:masterfrom
bryancall:fix/plugin-memory-leaks
Open

Fix memory leaks in plugins#13028
bryancall wants to merge 5 commits intoapache:masterfrom
bryancall:fix/plugin-memory-leaks

Conversation

@bryancall
Copy link
Copy Markdown
Contributor

@bryancall bryancall commented Mar 27, 2026

Summary

  • client_context_dump — missing free(results) after TSSslClientContextsNamesGet
  • origin_server_auth — add ConfigCache destructor to delete cached S3Config objects
  • stale_response — free log_info.filename when not the static default

Found via ASAN-enabled autest runs on Fedora 43.

Test plan

  • Built with ENABLE_ASAN=ON and ran full autest suite — no new LSAN reports for these symbols
  • CI

The results array allocated via malloc() in CB_context_dump
was never freed after iterating over the context names.
The ConfigCache class stores raw S3Config pointers in its _cache
map but lacks a destructor, leaking all configs on shutdown. Add
a destructor that deletes all remaining S3Config pointers.
The global g_config linked list of HCFileInfo structs (and their
ok/miss buffers and HCFileData) were never freed. Add a shutdown
handler via TS_LIFECYCLE_SHUTDOWN_HOOK to walk the list and free
all allocations when the plugin shuts down.
The ConfigInfo destructor frees body_data and body_data_mutex
but never frees log_info.filename, which is allocated via
strdup() when the -d option is parsed. This adds a free()
call in the destructor, guarded by a check against the
default static PLUGIN_TAG pointer.
@bryancall bryancall added this to the 11.0.0 milestone Mar 27, 2026
@bryancall bryancall added Plugins Bug ASan Address Sanitizer labels Mar 27, 2026
@bryancall bryancall self-assigned this Mar 27, 2026
bryancall

This comment was marked as off-topic.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses several leak reports found via ASAN/LSAN runs by adding missing cleanup paths across multiple ATS plugins and examples.

Changes:

  • Free the results array in client_context_dump after TSSslClientContextsNamesGet().
  • Add shutdown-time cleanup for healthchecks global config list.
  • Add ConfigCache destructor cleanup in origin_server_auth and free stale_response’s dynamically allocated log filename.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
plugins/origin_server_auth/origin_server_auth.cc Adds ConfigCache destructor to delete cached S3Config objects.
plugins/healthchecks/healthchecks.cc Adds shutdown hook and helper to free the HCFileInfo linked list.
plugins/experimental/stale_response/stale_response.h Frees log_info.filename when it is dynamically allocated.
example/plugins/c-api/client_context_dump/client_context_dump.cc Frees the caller-allocated results array.

…own hook frees g_config while hc_thread is still running its infinite inotify loop, causing a use-after-free. Since this leak only occurs at process exit, let the OS reclaim the memory.
@bryancall
Copy link
Copy Markdown
Contributor Author

CI: Fedora failure is unrelated — test_cache_Update_Header (SEGFAULT) is a pre-existing flaky cache unit test. Retriggering.

/retest

@bryancall
Copy link
Copy Markdown
Contributor Author

[approve ci fedora]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ASan Address Sanitizer Bug Plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants