Skip to content

Commit 2a252e2

Browse files
committed
Fix: Fix lwIP memory leak on TC6 error.
See MicrochipTech/oa-tc6-lib@8cc5240 .
1 parent 805bf89 commit 2a252e2

File tree

2 files changed

+19
-38
lines changed

2 files changed

+19
-38
lines changed

Diff for: src/microchip/TC6_Arduino_10BASE_T1S.cpp

+12-37
Original file line numberDiff line numberDiff line change
@@ -398,58 +398,33 @@ void TC6_CB_OnRxEthernetSlice(TC6_t *pInst, const uint8_t *pRx, uint16_t offset,
398398
{
399399
TC6LwIP_t *lw = TC6::GetContextTC6(pInst);
400400
bool success = true;
401-
(void) pInst;
402-
(void) pGlobalTag;
401+
(void)pInst;
402+
(void)pGlobalTag;
403403
// TC6_ASSERT(lw->tc.tc6 == pInst);
404-
if (lw->tc.rxInvalid)
405-
{
404+
if (lw->tc.rxInvalid) {
406405
success = false;
407406
}
408-
if (success && ((offset + len) > TC6LwIP_MTU))
409-
{
410-
// PrintRateLimited("on_rx_slice:packet greater than MTU", (offset + len));
407+
if (success && ((offset + len) > TC6LwIP_MTU)) {
408+
// PRINT("on_rx_slice:packet greater than MTU", (offset + len));
411409
lw->tc.rxInvalid = true;
412410
success = false;
413411
}
414-
if (success && (0u != offset))
415-
{
416-
if (!lw->tc.pbuf || !lw->tc.rxLen)
417-
{
418-
// TC6_ASSERT(false);
419-
lw->tc.rxInvalid = true;
420-
success = false;
421-
}
422-
} else
423-
{
424-
if (success && (lw->tc.pbuf || lw->tc.rxLen))
425-
{
426-
// TC6_ASSERT(false);
412+
if (success && (NULL == lw->tc.pbuf)) {
413+
lw->tc.pbuf = pbuf_alloc(PBUF_RAW, TC6LwIP_MTU, PBUF_RAM);
414+
if (!lw->tc.pbuf) {
427415
lw->tc.rxInvalid = true;
428416
success = false;
429417
}
430-
431-
if (success)
432-
{
433-
lw->tc.pbuf = pbuf_alloc(PBUF_RAW, TC6LwIP_MTU, PBUF_RAM);
434-
if (!lw->tc.pbuf)
435-
{
436-
lw->tc.rxInvalid = true;
437-
success = false;
438-
}
439-
}
440-
if (success && (NULL != lw->tc.pbuf->next))
441-
{
442-
// TC6_ASSERT(lw->tc.pbuf->ref != 0);
443-
// PrintRateLimited("rx_slice: could not allocate unsegmented memory diff", (lw->tc.pbuf->tot_len - lw->tc.pbuf->len));
418+
if (success && (NULL != lw->tc.pbuf->next)) {
419+
// PRINT("rx_slice: could not allocate unsegmented memory diff", (lw->tc.pbuf->tot_len - lw->tc.pbuf->len));
444420
lw->tc.rxInvalid = true;
445421
pbuf_free(lw->tc.pbuf);
446422
lw->tc.pbuf = NULL;
447423
success = false;
448424
}
449425
}
450-
if (success)
451-
{
452-
(void) memcpy((uint8_t *) lw->tc.pbuf->payload + offset, pRx, len);
426+
if (success) {
427+
(void)memcpy(lw->tc.pbuf->payload + offset, pRx, len);
453428
lw->tc.rxLen += len;
454429
}
455430
}

Diff for: src/microchip/lib/libtc6/inc/tc6-regs.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ void TC6Regs_Reinit(TC6_t *pInst);
148148
*/
149149
bool TC6Regs_SetPlca(TC6_t *pInst, bool plcaEnable, uint8_t nodeId, uint8_t nodeCount);
150150

151+
/** \brief Returns the LAN865x Revision number.
152+
* \param pInst - The pointer returned by TC6_Init.
153+
* \return 0, in case of error. Otherwise, Chip Revision.
154+
*/
155+
uint8_t TC6Regs_GetChipRevision(TC6_t *pInst);
156+
151157
/** \brief Configure DIOAx GPIOs as output.
152158
*/
153159
void TC6Regs_EnableDio_A0(TC6_t *pTC6);
@@ -191,7 +197,7 @@ uint32_t TC6Regs_CB_GetTicksMs(void);
191197
void TC6Regs_CB_OnEvent(TC6_t *pInst, TC6Regs_Event_t event, void *pTag);
192198

193199
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
194-
/* CONVERSTION FUNCTIONS */
200+
/* CONVERSION FUNCTIONS */
195201
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
196202

197203
template <typename Enumeration>

0 commit comments

Comments
 (0)