diff --git a/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c b/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c index 04a65da37cb..e33cf760433 100644 --- a/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +++ b/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c @@ -260,6 +260,9 @@ static const rb_data_type_t cpu_and_wall_time_worker_typed_data = { static VALUE _native_new(VALUE klass) { struct cpu_and_wall_time_worker_state *state = ruby_xcalloc(1, sizeof(struct cpu_and_wall_time_worker_state)); + // Note: Any exceptions raised from this note until the TypedData_Wrap_Struct call will lead to the state memory + // being leaked. + state->gc_profiling_enabled = false; state->allocation_counting_enabled = false; state->no_signals_workaround_enabled = false; diff --git a/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c b/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c index 603df208ded..c3228de22f3 100644 --- a/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c +++ b/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c @@ -78,6 +78,9 @@ static const rb_data_type_t idle_sampling_helper_typed_data = { static VALUE _native_new(VALUE klass) { struct idle_sampling_loop_state *state = ruby_xcalloc(1, sizeof(struct idle_sampling_loop_state)); + // Note: Any exceptions raised from this note until the TypedData_Wrap_Struct call will lead to the state memory + // being leaked. + reset_state(state); return TypedData_Wrap_Struct(klass, &idle_sampling_helper_typed_data, state); diff --git a/ext/ddtrace_profiling_native_extension/collectors_thread_context.c b/ext/ddtrace_profiling_native_extension/collectors_thread_context.c index 44735400b98..ecfa2fb265a 100644 --- a/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +++ b/ext/ddtrace_profiling_native_extension/collectors_thread_context.c @@ -304,6 +304,9 @@ static int hash_map_per_thread_context_free_values(DDTRACE_UNUSED st_data_t _thr static VALUE _native_new(VALUE klass) { struct thread_context_collector_state *state = ruby_xcalloc(1, sizeof(struct thread_context_collector_state)); + // Note: Any exceptions raised from this note until the TypedData_Wrap_Struct call will lead to the state memory + // being leaked. + // Update this when modifying state struct state->sampling_buffer = NULL; state->hash_map_per_thread_context =