Skip to content

Commit

Permalink
Avoid memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
mubes committed Nov 29, 2024
1 parent 62b3a29 commit 83463c0
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions Src/orbtop.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,19 @@ uint32_t _consolodateReport( struct reportLine **returnReport, uint32_t *returnR
}
else
{
a = ( struct visitedAddr * )calloc( 1, sizeof( struct visitedAddr ) );
MEMCHECKV( a );
a->visits = _r.sleeps;

n = ( struct nameEntry * )malloc( sizeof( struct nameEntry ) );
}
n->fileindex = NO_FILE;
n->functionindex = FN_SLEEPING;
n->addr = FN_SLEEPING;
n->line = 0;

n->fileindex = NO_FILE;
n->functionindex = FN_SLEEPING;
n->addr = 0;
n->line = 0;
a->n = n;
HASH_ADD_INT( _r.addresses, n->addr, a );
}

report[reportLines].n = n;
report[reportLines].count = _r.sleeps;
Expand Down Expand Up @@ -808,16 +814,18 @@ void _handlePCSample( struct pcSampleMsg *m, struct ITMDecoder *i )
void _flushHash( void )

{
struct visitedAddr *a;
UT_hash_handle hh;
struct visitedAddr *a, *tmp;

for ( a = _r.addresses; a != NULL; a = hh.next )
HASH_ITER( hh, _r.addresses, a, tmp )
{
hh = a->hh;
if ( a->n )
{
free( a->n );
}

HASH_DEL( _r.addresses, a );
free( a );
}

_r.addresses = NULL;
}
// ====================================================================================================
// Pump characters into the itm decoder
Expand Down

0 comments on commit 83463c0

Please sign in to comment.