Skip to content

Commit

Permalink
Merge pull request #3972 from DataDog/ivoanjo/prof-10656-add-provisio…
Browse files Browse the repository at this point in the history
…nal-error-checking

[PROF-10656] Add extra error checking to heap profiling function
  • Loading branch information
ivoanjo authored Oct 3, 2024
2 parents 9a012ec + 2ece812 commit 40837e3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ext/datadog_profiling_native_extension/heap_recorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,20 @@ static void cleanup_heap_record_if_unused(heap_recorder *heap_recorder, heap_rec
}

static void on_committed_object_record_cleanup(heap_recorder *heap_recorder, object_record *record) {
// @ivoanjo: We've seen a segfault crash in the field in this function (October 2024) which we're still trying to investigate.
// (See PROF-10656 Datadog-internal for details). Just in case, I've sprinkled a bunch of NULL tests in this function for now.
// Once we figure out the issue we can get rid of them again.

if (heap_recorder == NULL) rb_raise(rb_eRuntimeError, "heap_recorder was NULL in on_committed_object_record_cleanup");
if (heap_recorder->heap_records == NULL) rb_raise(rb_eRuntimeError, "heap_recorder->heap_records was NULL in on_committed_object_record_cleanup");
if (record == NULL) rb_raise(rb_eRuntimeError, "record was NULL in on_committed_object_record_cleanup");

// Starting with the associated heap record. There will now be one less tracked object pointing to it
heap_record *heap_record = record->heap_record;

if (heap_record == NULL) rb_raise(rb_eRuntimeError, "heap_record was NULL in on_committed_object_record_cleanup");
if (heap_record->stack == NULL) rb_raise(rb_eRuntimeError, "heap_record->stack was NULL in on_committed_object_record_cleanup");

heap_record->num_tracked_objects--;

// One less object using this heap record, it may have become unused...
Expand Down

0 comments on commit 40837e3

Please sign in to comment.