[En-Nut-Discussion] Is this a bug or a 'Feature' ?

Mike Cornelius mikec at calldirect.com.au
Thu Apr 3 07:41:00 CEST 2003


Hi All,

I've found that the following code:-

while (1)
{
	addr = inet_addr("192.168.1.117");

	loc_sock = NutTcpCreateSocket();
	loc_sock->so_read_to = 1000;

	if(NutTcpConnect(loc_sock, addr, MODBUS_PORT) == 0)
	{
		// Stuff that doesn't matter
	}

	NutTcpCloseSocket(loc_sock);
}

Does not actually free the memory associated with the socket if
NutTcpConnect() fails, particularly in the case where I disconnect the
ethernet cable.

NutTcpCloseSocket() calls NutTcpStateCloseEvent() and if sock->so_state ==
TCPS_CLOSED at that time NutTcpStateCloseEvent() sets:-

sock->so_last_error = ENOTCONN;

Which sort of makes sense but requires the application to check the
NutTcpCloseSocket() return value and 'manually' call NutTcpDestroySocket()
otherwise we've got a memory leak.

To me it makes sense to modify NutTcpStateCloseEvent() as follows: -
    case TCPS_CLOSED: // <-New Case
    case TCPS_LISTEN:
    case TCPS_SYN_SENT:
        /*
         * No connection yet, immediately destroy the socket.
         */
        NutTcpDestroySocket(sock);
        break;

I wonder what others (Particularly Harald) think...


Regards,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mike Cornelius                      Internet: mikec at calldirect.com.au
Call Direct Cellular Solutions      Phone:    +61 2 99-65-75-85
Level 1 8-22 West St North Sydney   FAX:      +61 2 99-65-75-90
NSW 2060 Australia                  URL:      http://www.calldirect.com.au
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





More information about the En-Nut-Discussion mailing list