Skip to content

Commit 1f37473

Browse files
committed
fix(profiling): crash in ddtrace_get_profiling_context
1 parent 3112dff commit 1f37473

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

ext/profiling.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ ZEND_EXTERN_MODULE_GLOBALS(ddtrace);
88

99
DDTRACE_PUBLIC struct ddtrace_profiling_context ddtrace_get_profiling_context(void) {
1010
struct ddtrace_profiling_context context = {0, 0};
11-
if (DDTRACE_G(active_stack) && DDTRACE_G(active_stack)->root_span && get_DD_TRACE_ENABLED()) {
11+
// NOTE: `active_stack->active` may legitimately be NULL during span close (e.g. when closing the last span on a
12+
// stack, `ddtrace_close_top_span_without_stack_swap()` updates it before running additional logic that may still
13+
// allocate, such as JSON encoding during sampling decisions). Allocation profiling can call into this function
14+
// from within those allocations, so treat "no active span" as "no profiling context" instead of dereferencing.
15+
if (DDTRACE_G(active_stack) && DDTRACE_G(active_stack)->root_span && DDTRACE_G(active_stack)->active && get_DD_TRACE_ENABLED()) {
1216
context.local_root_span_id = DDTRACE_G(active_stack)->root_span->span_id;
1317
context.span_id = SPANDATA(DDTRACE_G(active_stack)->active)->span_id;
1418
}

0 commit comments

Comments
 (0)