Skip to content

Fix use-after-free in IPC client connection lifetime management#6

Merged
jrosdahl merged 1 commit intoccache:mainfrom
kica-z:main
Apr 22, 2026
Merged

Fix use-after-free in IPC client connection lifetime management#6
jrosdahl merged 1 commit intoccache:mainfrom
kica-z:main

Conversation

@kica-z
Copy link
Copy Markdown
Contributor

@kica-z kica-z commented Apr 22, 2026

During our builds we did get coredumps of the storage helper. After some investigation it seems like those where caused by a heap memory corruption.

After analysis to me it seems like this could be the reason:

  • Problem:
    • Async storage callbacks captured the client by reference, causing use-after-free when the connection closed before the HTTP response arrived.
  • Fix:
    • Switching ClientConnection to shared_ptr ownership: the server tracks clients in an unordered_map and callbacks capture a shared_ptr so the object stays alive until all in-flight requests complete. A disconnected flag prevents writing to a closed pipe.

Async storage callbacks captured the client by reference, causing
use-after-free when the connection closed before the HTTP response
arrived.

Fix by switching ClientConnection to shared_ptr ownership: the server
tracks clients in an unordered_map and callbacks capture a shared_ptr
so the object stays alive until all in-flight requests complete. A
disconnected flag prevents writing to a closed pipe.
@kica-z kica-z mentioned this pull request Apr 22, 2026
@jrosdahl
Copy link
Copy Markdown
Member

Good catch, thanks! I'll make an additional robustness fix as a follow-up.

@jrosdahl jrosdahl merged commit 753dc63 into ccache:main Apr 22, 2026
2 checks passed
jrosdahl added a commit that referenced this pull request Apr 22, 2026
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.

2 participants