Skip to content

Commit

Permalink
Merge pull request #973 from tony-josi-aws/fix_buffers_getting_lost
Browse files Browse the repository at this point in the history
Free old network buffers once its duplicated
  • Loading branch information
tony-josi-aws authored Jul 19, 2023
2 parents 0277044 + 7f7b5a6 commit 3e26a33
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion source/FreeRTOS_ND.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,14 +573,17 @@
IPv6_Address_t xTargetIPAddress;
MACAddress_t xMultiCastMacAddress;
NetworkBufferDescriptor_t * pxDescriptor = pxNetworkBuffer;
NetworkBufferDescriptor_t * pxNewDescriptor = NULL;

if( ( pxEndPoint != NULL ) && ( pxEndPoint->bits.bIPv6 != pdFALSE_UNSIGNED ) )
{
uxNeededSize = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( ICMPHeader_IPv6_t );

if( pxDescriptor->xDataLength < uxNeededSize )
{
pxDescriptor = pxDuplicateNetworkBufferWithDescriptor( pxDescriptor, uxNeededSize );
pxNewDescriptor = pxDuplicateNetworkBufferWithDescriptor( pxDescriptor, uxNeededSize );
vReleaseNetworkBufferAndDescriptor( pxDescriptor );
pxDescriptor = pxNewDescriptor;
}

if( pxDescriptor != NULL )
Expand Down
5 changes: 4 additions & 1 deletion source/FreeRTOS_RA.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
NetworkBufferDescriptor_t * pxDescriptor = pxNetworkBuffer;
IPv6_Address_t xSourceAddress;
BaseType_t xHasLocal;
NetworkBufferDescriptor_t * pxNewDescriptor = NULL;

configASSERT( pxEndPoint != NULL );
configASSERT( pxEndPoint->bits.bIPv6 != pdFALSE_UNSIGNED );
Expand All @@ -156,7 +157,9 @@

if( pxDescriptor->xDataLength < uxNeededSize )
{
pxDescriptor = pxDuplicateNetworkBufferWithDescriptor( pxDescriptor, uxNeededSize );
pxNewDescriptor = pxDuplicateNetworkBufferWithDescriptor( pxDescriptor, uxNeededSize );
vReleaseNetworkBufferAndDescriptor( pxDescriptor );
pxDescriptor = pxNewDescriptor;
}

if( pxDescriptor != NULL )
Expand Down
2 changes: 2 additions & 0 deletions test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ void test_vNDAgeCache_NSIncorrectDataLen( void )

pxDuplicateNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( NULL );

vReleaseNetworkBufferAndDescriptor_Expect( &xNetworkBuffer );

vNDAgeCache();

TEST_ASSERT_EQUAL( xNDCache[ xUseEntry ].ucAge, xAgeDefault - 1 );
Expand Down
8 changes: 8 additions & 0 deletions test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ void test_vNDSendRouterSolicitation_xHasLocal0( void )

pxDuplicateNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( NULL );

vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer );

vNDSendRouterSolicitation( pxNetworkBuffer, &xIPAddress );
}

Expand Down Expand Up @@ -188,6 +190,8 @@ void test_vNDSendRouterSolicitation_xHasLocal1( void )

pxDuplicateNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( NULL );

vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer );

vNDSendRouterSolicitation( pxNetworkBuffer, &xIPAddress );
}

Expand Down Expand Up @@ -223,6 +227,8 @@ void test_vNDSendRouterSolicitation_NullDesc( void )

pxDuplicateNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( NULL );

vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer );

vNDSendRouterSolicitation( pxNetworkBuffer, &xIPAddress );
}

Expand Down Expand Up @@ -1017,6 +1023,8 @@ void test_vRAProcess_eRAStateApply2( void )
/*usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( ipCORRECT_CRC ); */
/*vReturnEthernetFrame_ExpectAnyArgs(); */

vReleaseNetworkBufferAndDescriptor_Expect( &xNetworkBuffer );

vDHCP_RATimerReload_ExpectAnyArgs();

/* pdFALSE for vRAProcessInit */
Expand Down

0 comments on commit 3e26a33

Please sign in to comment.