Skip to content

Commit

Permalink
Merge pull request #10208 from evgeny-leksikov/ucs_memtrack_dump
Browse files Browse the repository at this point in the history
UCS/MEMTRACK: fix allocation on memtrack dump
  • Loading branch information
yosefe authored Oct 6, 2024
2 parents ba58fae + 6f0ae65 commit 63ce776
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/ucs/debug/memtrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,17 @@ static void ucs_memtrack_dump_internal(FILE* output_stream)
return;
}

/* collect all entries to one array */
all_entries = ucs_alloca(sizeof(*all_entries) *
kh_size(&ucs_memtrack_context.entries));
/* collect all entries to one array
* - do not use ucs_alloca() since stack may have not enough space
* - do not use ucs_malloc since it affects memtrack structures
*/
all_entries = malloc(sizeof(*all_entries) *
kh_size(&ucs_memtrack_context.entries));
if (all_entries == NULL) {
ucs_error("cannot allocate memory to dump memtrack entries");
return;
}

num_entries = 0;
kh_foreach_value(&ucs_memtrack_context.entries, entry, {
all_entries[num_entries++] = entry;
Expand All @@ -158,6 +166,8 @@ static void ucs_memtrack_dump_internal(FILE* output_stream)
fprintf(output_stream, UCS_MEMTRACK_FORMAT_STRING, entry->name,
entry->size, entry->peak_size, entry->count, entry->peak_count);
}

free(all_entries);
}

static void ucs_memtrack_generate_report()
Expand Down

0 comments on commit 63ce776

Please sign in to comment.