Skip to content

Commit

Permalink
Fix some memory leaks in heap profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Jan 8, 2021
1 parent 3171bdb commit 66b5bf8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/profiler/heapsnapshot.c
Expand Up @@ -798,11 +798,22 @@ static void record_snapshot(MVMThreadContext *tc, MVMHeapSnapshotCollection *col
static void destroy_current_heap_snapshot(MVMThreadContext *tc) {
MVMHeapSnapshotCollection *col = tc->instance->heap_snapshots;

MVM_free(col->snapshot->stats->type_counts);
MVM_free(col->snapshot->stats->type_size_sum);
MVM_free(col->snapshot->stats->sf_counts);
MVM_free(col->snapshot->stats->sf_size_sum);
MVM_free(col->snapshot->stats);
MVM_free(col->snapshot->collectables);
MVM_free(col->snapshot->references);
MVM_free_null(col->snapshot);
}

static void destroy_toc(MVMHeapDumpTableOfContents *toc) {
MVM_free(toc->toc_words);
MVM_free(toc->toc_positions);
MVM_free(toc);
}

/* Frees all memory associated with the heap snapshot. */
static void destroy_heap_snapshot_collection(MVMThreadContext *tc) {
MVMHeapSnapshotCollection *col = tc->instance->heap_snapshots;
Expand All @@ -818,9 +829,9 @@ static void destroy_heap_snapshot_collection(MVMThreadContext *tc) {
MVM_free(col->static_frames);

#if MVM_HEAPSNAPSHOT_FORMAT == 3
MVM_free(col->toplevel_toc);
destroy_toc(col->toplevel_toc);
if (col->second_level_toc)
MVM_free(col->second_level_toc);
destroy_toc(col->second_level_toc);
#elif MVM_HEAPSNAPSHOT_FORMAT == 2
MVM_free(col->index->snapshot_sizes);
MVM_free(col->index);
Expand Down

0 comments on commit 66b5bf8

Please sign in to comment.