[En-Nut-Discussion] Fwd: Memory Leaks with Routes, Opening and Closing ppp devices

Harald Kipp harald.kipp at egnite.de
Tue Nov 11 19:43:57 CET 2003


>Delivered-To: web2p2 at p15095813.pureserver.info
>Date: Tue, 11 Nov 2003 23:04:14 +1300
>From: Brett Abbott
>Subject: Memory Leaks with Routes, Opening and Closing ppp devices
>To: en-nut-discussion at egnite.de
>Organization: Digital Telemetry Ltd
>X-Accept-Language: en-us, en
>User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4)
>  Gecko/20030624 Netscape/7.1 (ax)
>
>Hi
>
>When opening a PPP device, 3 routes are typically added as part of the 
>process as well as opening the uart device.  These routes are not deleted 
>when the device is closed.  This results in a memory leak (at least on my 
>box).  When reopened, the routes are re-added which doesnt impact service, 
>just uses more memory.
>
>Has anyone else noticed this?
>
>I attach the code Ive added to route.c which provides the means to purge 
>routes associated with a named device prior to closing it.  Perhaps it 
>could be called within the close process for network devices.  Harald, 
>what do you think?
>
>An example of usage might be:
>
>                pppdev = NutDeviceLookup("ppp");
>                NutIpRoutePurge(pppdev);
>
>                   if (_close(pppcom) == 0)
>                {
>                    ppp_hackup = 0;
>                    pppcom=-1;
>                }
>
>Thanks!
>Brett
>
>/*!
>* \brief Purge Route entries for a named device
>*
>* This process used prior to closing a device
>*
>* \param dev  Network interface for which routes are to be purged
>*
>* \return 0 on success, -1 otherwise.
>*/
>int NutIpRoutePurge(NUTDEVICE * dev)
>{
>    int rc = -1;
>    RTENTRY *rte;
>    RTENTRY *rte_next;
>    RTENTRY *rte_prev;
>
>    AtomicInc(&rteLock);
>    NutEnterCritical();
>    if (rteLock == 1) {
>
>        /* Go through route table looking for our device
>         * Purge records that match and repair linked list as we go
>         */
>
>        rte = rteList; // Start by looking at the top of the List
>        rte_prev = 0; // Keep track of the previous one
>
>        // Work through the list till no more
>        while (rte) {
>            rte_next=rte->rt_next;
>
>            if(rte->rt_dev == dev) { // Found one to purge
>                if (rte_prev) { // Take it out of the linked list
>                    // It wasnt the first in the list so link previous to next
>                    rte_prev->rt_next=rte->rt_next;
>                } else {
>                    // It was the first in the list, move the start of the 
> list
>                    rteList=rte->rt_next;
>                }
>
>                // Now free memory used by the purged route
>                NutHeapFree(rte);
>
>            } else {
>                // We are leaving one intact so advance the rte_prev 
> pointer to this one
>                // Note that if we had deleted an entry, the rte_prev 
> pointer will stay still
>                rte_prev=rte;
>            }
>
>            // Get ready to look at next one
>            rte=rte_next;
>        }
>        rc=0;
>
>    }
>    NutExitCritical();
>    AtomicDec(&rteLock);
>
>    return rc;
>}
>
>--
>-----------------------------------------------------------------
>Brett Abbott, Managing Director, Digital Telemetry Limited
>Email: Brett.Abbott at digital-telemetry.com
>PO Box 24 036 Manners Street, Wellington, New Zealand
>Phone +64 (4) 5666-860  Mobile +64 (21) 656-144
>------------------- Commercial in confidence --------------------
>
>




More information about the En-Nut-Discussion mailing list