[En-Nut-Discussion] UDP Memory leak fix

Ralph Mason ralph.mason at telogis.com
Mon Apr 14 23:11:32 CEST 2003


I noticed that memory could lead from a UPD socket if the user called
Destroy and there was unread data on the socket.

Fixed Below

Ralph



/*!
 * \brief Close UDP socket.
 *
 * The memory occupied by the socket is immediately released
 * after calling this function. The application  must not use
 * the socket after this call.
 *
 * \param sock Socket descriptor. This pointer must have been
 *             retrieved by calling NutUdpCreateSocket().
 *
 * \return 0 on success, -1 otherwise.
 */
int NutUdpDestroySocket(UDPSOCKET * sock)
{
    UDPSOCKET *sp;
    UDPSOCKET **spp;
    int rc = -1;

    spp = &udpSocketList;
    sp = udpSocketList;

    while (sp) {
        if (sp == sock) {
            *spp = sock->so_next;

            /* A packet may have arrived that the application
			   Did not read before closing the socket
			 */
            if ( sock->so_rx_nb != 0 ){
			NutNetBufFree(sock->so_rx_nb);
            }

            NutHeapFree(sock);
            rc = 0;
            break;
        }
        spp = &sp->so_next;
        sp = sp->so_next;
    }
    return rc;
}
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.461 / Virus Database: 260 - Release Date: 10/03/2003




More information about the En-Nut-Discussion mailing list