Skip to content

Commit bbd8d23

Browse files
fix(profiling): guard against invalid access on exit
Co-authored-by: KowalskiThomas <14239160+KowalskiThomas@users.noreply.github.com>
1 parent 7edf894 commit bbd8d23

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

ddtrace/internal/datadog/profiling/stack/include/sampler.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Sampler
3838

3939
// This is a singleton, so no public constructor
4040
Sampler();
41+
~Sampler();
4142

4243
// One-time setup of echion
4344
void one_time_setup();

ddtrace/internal/datadog/profiling/stack/src/sampler.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ Sampler::Sampler()
258258
{
259259
}
260260

261+
Sampler::~Sampler()
262+
{
263+
stop();
264+
if (thread_running.load()) {
265+
// The sampling thread is still alive after the timeout in stop().
266+
// Leak the EchionSampler so the thread does not access destroyed
267+
// data structures (StringTable, FrameCache, etc.) — this prevents
268+
// a SIGSEGV in the hash-table code during process exit.
269+
(void)echion.release();
270+
}
271+
}
272+
261273
Sampler&
262274
Sampler::get()
263275
{
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
fixes:
3+
- |
4+
profiling: This fix resolves a SIGSEGV crash (in ``StringTable::key``) that occurred when the
5+
profiling sampling thread was still running during process exit. The Sampler singleton's
6+
default destructor destroyed the ``EchionSampler`` (and its hash tables) while the detached
7+
sampling thread was still accessing them. The fix adds an explicit destructor that calls
8+
``stop()`` and, if the thread does not exit in time, leaks the ``EchionSampler`` to prevent
9+
use-after-free.

0 commit comments

Comments
 (0)