From ac2175fa7de5f9f6e248ae40201b1491bc898895 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Thu, 16 Feb 2012 12:55:14 +0100 Subject: [PATCH] fixed pbuf leak when PPP session is aborted through pppSigHUP() (bug #35541: PPP Memory Leak) --- CHANGELOG | 4 ++++ src/netif/ppp/ppp.c | 26 ++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ab28771d..f484d992 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -76,6 +76,10 @@ HISTORY ++ Bugfixes: + 2012-02-16: Simon Goldschmidt + * ppp.c: fixed pbuf leak when PPP session is aborted through pppSigHUP() + (bug #35541: PPP Memory Leak) + 2012-02-16: Simon Goldschmidt * etharp.c: fixed bug #35531: Impossible to send multicast without a gateway (introduced when fixing bug# 33551) diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 90eaf84b..06d9699f 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -243,6 +243,7 @@ static void pppInputThread(void *arg); #endif /* PPP_INPROC_OWNTHREAD */ static void pppDrop(PPPControlRx *pcrx); static void pppInProc(PPPControlRx *pcrx, u_char *s, int l); +static void pppFreeCurrentInputPacket(PPPControlRx *pcrx); #endif /* PPPOS_SUPPORT */ @@ -551,6 +552,8 @@ pppOverSerialOpen(sio_fd_t fd, pppLinkStatusCB_fn linkStatusCB, void *linkStatus pd = PPPERR_OPEN; } else { pc = &pppControl[pd]; + /* input pbuf left over from last session? */ + pppFreeCurrentInputPacket(&pc->rx); /* @todo: is this correct or do I overwrite something? */ memset(pc, 0, sizeof(PPPControl)); pc->rx.pd = pd; @@ -1723,6 +1726,22 @@ out: * Drop the input packet. */ static void +pppFreeCurrentInputPacket(PPPControlRx *pcrx) +{ + if (pcrx->inHead != NULL) { + if (pcrx->inTail && (pcrx->inTail != pcrx->inHead)) { + pbuf_free(pcrx->inTail); + } + pbuf_free(pcrx->inHead); + pcrx->inHead = NULL; + } + pcrx->inTail = NULL; +} + +/* + * Drop the input packet and increase error counters. + */ +static void pppDrop(PPPControlRx *pcrx) { if (pcrx->inHead != NULL) { @@ -1730,13 +1749,8 @@ pppDrop(PPPControlRx *pcrx) PPPDEBUG(LOG_INFO, ("pppDrop: %d:%.*H\n", pcrx->inHead->len, min(60, pcrx->inHead->len * 2), pcrx->inHead->payload)); #endif PPPDEBUG(LOG_INFO, ("pppDrop: pbuf len=%d, addr %p\n", pcrx->inHead->len, (void*)pcrx->inHead)); - if (pcrx->inTail && (pcrx->inTail != pcrx->inHead)) { - pbuf_free(pcrx->inTail); - } - pbuf_free(pcrx->inHead); - pcrx->inHead = NULL; - pcrx->inTail = NULL; } + pppFreeCurrentInputPacket(pcrx); #if VJ_SUPPORT vj_uncompress_err(&pppControl[pcrx->pd].vjComp); #endif /* VJ_SUPPORT */