Skip to content

Commit

Permalink
Fix: Fix lwIP memory leak on TC6 error.
Browse files Browse the repository at this point in the history
  • Loading branch information
aentinger committed Oct 2, 2024
1 parent 805bf89 commit 2a252e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 38 deletions.
49 changes: 12 additions & 37 deletions src/microchip/TC6_Arduino_10BASE_T1S.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,58 +398,33 @@ void TC6_CB_OnRxEthernetSlice(TC6_t *pInst, const uint8_t *pRx, uint16_t offset,
{
TC6LwIP_t *lw = TC6::GetContextTC6(pInst);
bool success = true;
(void) pInst;
(void) pGlobalTag;
(void)pInst;
(void)pGlobalTag;
// TC6_ASSERT(lw->tc.tc6 == pInst);
if (lw->tc.rxInvalid)
{
if (lw->tc.rxInvalid) {
success = false;
}
if (success && ((offset + len) > TC6LwIP_MTU))
{
// PrintRateLimited("on_rx_slice:packet greater than MTU", (offset + len));
if (success && ((offset + len) > TC6LwIP_MTU)) {
// PRINT("on_rx_slice:packet greater than MTU", (offset + len));
lw->tc.rxInvalid = true;
success = false;
}
if (success && (0u != offset))
{
if (!lw->tc.pbuf || !lw->tc.rxLen)
{
// TC6_ASSERT(false);
lw->tc.rxInvalid = true;
success = false;
}
} else
{
if (success && (lw->tc.pbuf || lw->tc.rxLen))
{
// TC6_ASSERT(false);
if (success && (NULL == lw->tc.pbuf)) {
lw->tc.pbuf = pbuf_alloc(PBUF_RAW, TC6LwIP_MTU, PBUF_RAM);
if (!lw->tc.pbuf) {
lw->tc.rxInvalid = true;
success = false;
}

if (success)
{
lw->tc.pbuf = pbuf_alloc(PBUF_RAW, TC6LwIP_MTU, PBUF_RAM);
if (!lw->tc.pbuf)
{
lw->tc.rxInvalid = true;
success = false;
}
}
if (success && (NULL != lw->tc.pbuf->next))
{
// TC6_ASSERT(lw->tc.pbuf->ref != 0);
// PrintRateLimited("rx_slice: could not allocate unsegmented memory diff", (lw->tc.pbuf->tot_len - lw->tc.pbuf->len));
if (success && (NULL != lw->tc.pbuf->next)) {
// PRINT("rx_slice: could not allocate unsegmented memory diff", (lw->tc.pbuf->tot_len - lw->tc.pbuf->len));
lw->tc.rxInvalid = true;
pbuf_free(lw->tc.pbuf);
lw->tc.pbuf = NULL;
success = false;
}
}
if (success)
{
(void) memcpy((uint8_t *) lw->tc.pbuf->payload + offset, pRx, len);
if (success) {
(void)memcpy(lw->tc.pbuf->payload + offset, pRx, len);
lw->tc.rxLen += len;
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/microchip/lib/libtc6/inc/tc6-regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ void TC6Regs_Reinit(TC6_t *pInst);
*/
bool TC6Regs_SetPlca(TC6_t *pInst, bool plcaEnable, uint8_t nodeId, uint8_t nodeCount);

/** \brief Returns the LAN865x Revision number.
* \param pInst - The pointer returned by TC6_Init.
* \return 0, in case of error. Otherwise, Chip Revision.
*/
uint8_t TC6Regs_GetChipRevision(TC6_t *pInst);

/** \brief Configure DIOAx GPIOs as output.
*/
void TC6Regs_EnableDio_A0(TC6_t *pTC6);
Expand Down Expand Up @@ -191,7 +197,7 @@ uint32_t TC6Regs_CB_GetTicksMs(void);
void TC6Regs_CB_OnEvent(TC6_t *pInst, TC6Regs_Event_t event, void *pTag);

/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
/* CONVERSTION FUNCTIONS */
/* CONVERSION FUNCTIONS */
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/

template <typename Enumeration>
Expand Down

0 comments on commit 2a252e2

Please sign in to comment.