Skip to content

Commit 40837e3

Browse files
authored
Merge pull request #3972 from DataDog/ivoanjo/prof-10656-add-provisional-error-checking
[PROF-10656] Add extra error checking to heap profiling function
2 parents 9a012ec + 2ece812 commit 40837e3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ext/datadog_profiling_native_extension/heap_recorder.c

+12
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,20 @@ static void cleanup_heap_record_if_unused(heap_recorder *heap_recorder, heap_rec
784784
}
785785

786786
static void on_committed_object_record_cleanup(heap_recorder *heap_recorder, object_record *record) {
787+
// @ivoanjo: We've seen a segfault crash in the field in this function (October 2024) which we're still trying to investigate.
788+
// (See PROF-10656 Datadog-internal for details). Just in case, I've sprinkled a bunch of NULL tests in this function for now.
789+
// Once we figure out the issue we can get rid of them again.
790+
791+
if (heap_recorder == NULL) rb_raise(rb_eRuntimeError, "heap_recorder was NULL in on_committed_object_record_cleanup");
792+
if (heap_recorder->heap_records == NULL) rb_raise(rb_eRuntimeError, "heap_recorder->heap_records was NULL in on_committed_object_record_cleanup");
793+
if (record == NULL) rb_raise(rb_eRuntimeError, "record was NULL in on_committed_object_record_cleanup");
794+
787795
// Starting with the associated heap record. There will now be one less tracked object pointing to it
788796
heap_record *heap_record = record->heap_record;
797+
798+
if (heap_record == NULL) rb_raise(rb_eRuntimeError, "heap_record was NULL in on_committed_object_record_cleanup");
799+
if (heap_record->stack == NULL) rb_raise(rb_eRuntimeError, "heap_record->stack was NULL in on_committed_object_record_cleanup");
800+
789801
heap_record->num_tracked_objects--;
790802

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

0 commit comments

Comments
 (0)