diff --git a/ddtrace/profiling/collector/_memalloc_heap.c b/ddtrace/profiling/collector/_memalloc_heap.c index 16d30440d10..66c4c6807ba 100644 --- a/ddtrace/profiling/collector/_memalloc_heap.c +++ b/ddtrace/profiling/collector/_memalloc_heap.c @@ -162,8 +162,10 @@ memalloc_heap_track(uint16_t max_nframe, void* ptr, size_t size) if (global_heap_tracker.allocated_memory < global_heap_tracker.current_sample_size) return false; - /* Cannot add more sample */ - if (global_heap_tracker.allocs.count >= TRACEBACK_ARRAY_MAX_COUNT) + /* Check if we can add more samples: the sum of the freezer + alloc tracker + cannot be greater than what the alloc tracker can handle: when the alloc + tracker is thawed, all the allocs in the freezer will be moved there!*/ + if ((global_heap_tracker.freezer.allocs.count + global_heap_tracker.allocs.count) >= TRACEBACK_ARRAY_MAX_COUNT) return false; traceback_t* tb = memalloc_get_traceback(max_nframe, ptr, global_heap_tracker.allocated_memory); diff --git a/releasenotes/notes/profiler-heap-max-alloc-bugfix-646423cdd7f7811f.yaml b/releasenotes/notes/profiler-heap-max-alloc-bugfix-646423cdd7f7811f.yaml new file mode 100644 index 00000000000..d7353a096d8 --- /dev/null +++ b/releasenotes/notes/profiler-heap-max-alloc-bugfix-646423cdd7f7811f.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fix a possible bug in the heap memory profiler that could trigger an + overflow when too many allocations were being tracked.