Skip to content

Commit 45ffa58

Browse files
authored
fix(profiling/heap): use the right integer type to iterate over freezer frees (backport #3174) (#3176)
This is an automatic backport of pull request #3174 done by [Mergify](https://mergify.com). --- <details> <summary>Mergify commands and options</summary> <br /> More conditions and actions can be found in the [documentation](https://docs.mergify.com/). You can also trigger Mergify actions by commenting on this pull request: - `@Mergifyio refresh` will re-evaluate the rules - `@Mergifyio rebase` will rebase this PR on its base branch - `@Mergifyio update` will merge the base branch into this PR - `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch Additionally, on Mergify [dashboard](https://dashboard.mergify.com/) you can: - look at your merge queues - generate the Mergify configuration with the config editor. Finally, you can contact us on https://mergify.com </details>
1 parent 7f65cbc commit 45ffa58

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

ddtrace/profiling/collector/_memalloc_heap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ heap_tracker_thaw(heap_tracker_t* heap_tracker)
103103
array together to be sure that there's no free in the freezer matching
104104
an alloc that is also in the freezer; heap_tracker_untrack_thawed does
105105
not care about the freezer, by definition. */
106-
for (TRACEBACK_ARRAY_COUNT_TYPE i = 0; i < heap_tracker->freezer.frees.count; i++)
106+
for (MEMALLOC_HEAP_PTR_ARRAY_COUNT_TYPE i = 0; i < heap_tracker->freezer.frees.count; i++)
107107
heap_tracker_untrack_thawed(heap_tracker, heap_tracker->freezer.frees.tab[i]);
108108

109109
/* Reset the count to zero so we can reused the array and overwrite previous values */
@@ -149,9 +149,9 @@ memalloc_heap_untrack(void* ptr)
149149
enough space, we ignore the untrack. That's sad as there is a change
150150
the heap profile won't be valid anymore. However, that's the best we
151151
can do since reporting an error is not an option here. What's gonna
152-
free more than 2^64 pointer anyway?!
152+
free more than 2^64 pointers anyway?!
153153
*/
154-
if (global_heap_tracker.freezer.frees.count < MEMALLOC_HEAP_PTR_ARRAY_MAX)
154+
if (global_heap_tracker.freezer.frees.count < MEMALLOC_HEAP_PTR_ARRAY_MAX_COUNT)
155155
ptr_array_append(&global_heap_tracker.freezer.frees, ptr);
156156
} else
157157
heap_tracker_untrack_thawed(&global_heap_tracker, ptr);

ddtrace/profiling/collector/_memalloc_heap.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ memalloc_heap_track(uint16_t max_nframe, void* ptr, size_t size);
2525
void
2626
memalloc_heap_untrack(void* ptr);
2727

28-
#define MEMALLOC_HEAP_PTR_ARRAY_MAX UINT64_MAX
29-
DO_ARRAY(void *, ptr, uint64_t, DO_NOTHING)
28+
#define MEMALLOC_HEAP_PTR_ARRAY_COUNT_TYPE uint64_t
29+
#define MEMALLOC_HEAP_PTR_ARRAY_MAX_COUNT UINT64_MAX
30+
DO_ARRAY(void *, ptr, MEMALLOC_HEAP_PTR_ARRAY_COUNT_TYPE, DO_NOTHING)
3031

3132
#endif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Fix a bug in the heap profiler that could be triggered if more than 2^16
5+
memory items were freed during heap data collection.

0 commit comments

Comments
 (0)