Skip to content

Commit

Permalink
Add reminder to be careful with raising exceptions in native object a…
Browse files Browse the repository at this point in the history
…llocators
  • Loading branch information
ivoanjo committed Sep 28, 2023
1 parent b90b5d4 commit 8b5031f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 8b5031f

Please sign in to comment.