Skip to content

Commit

Permalink
FreeRTOS_TCP_WIN_utest.c: Fix memory leaks of type free(NULL)
Browse files Browse the repository at this point in the history
The pointer to the allocated memory was reset. ⏚
  • Loading branch information
anordal committed May 26, 2024
1 parent 818fad0 commit 8fc5a6b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,14 @@ void test_vTCPSegmentCleanup_segment_null( void )
void test_vTCPSegmentCleanup_segment_not_null( void )
{
/* will be freed by the function under test */
xTCPSegments = ( TCPSegment_t * ) malloc( 123 );
TCPSegment_t * pxTCPSegment = malloc( sizeof( TCPSegment_t ) );

xTCPSegments = pxTCPSegment;

vPortFree_Expect( xTCPSegments );
vTCPSegmentCleanup();
TEST_ASSERT_NULL( xTCPSegments );
free( pxTCPSegment );
}

void test_lTCPWindowRxCheck_sequence_nums_equal( void )
Expand Down Expand Up @@ -1233,7 +1236,9 @@ void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_gt_maxlen( void )
int32_t lMax = 0;

/* in real code, this points to a list of segments */
xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) );
TCPSegment_t * pxTCPSegment = malloc( sizeof( TCPSegment_t ) );

xWindow.pxHeadSegment = pxTCPSegment;
xWindow.pxHeadSegment->lMaxLength = 300;
xWindow.pxHeadSegment->lDataLength = 200;
xWindow.pxHeadSegment->u.bits.bOutstanding = pdTRUE_UNSIGNED;
Expand Down Expand Up @@ -1265,7 +1270,7 @@ void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_gt_maxlen( void )

TEST_ASSERT_EQUAL( 25, lDone );
TEST_ASSERT_NULL( xWindow.pxHeadSegment );
free( xWindow.pxHeadSegment );
free( pxTCPSegment );
}

void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_lt_maxlen( void )
Expand Down

0 comments on commit 8fc5a6b

Please sign in to comment.