Problem
The sample SMUX code provided in /usr/src/cmd/net/smux-samp/foosmuxd.c contains a "memory leak".
Each time foosmuxd handles an incoming request (for example, from
/etc/getone), the foosmuxd process allocates a small amount of
memory, but then fails to free it up. Therefore, the size of the
foosmuxd process (as shown by ps -el) continues to grow larger
with time. Cause
The system library routine smux_wait() allocates memory for an SMUX
PDU structure and returns a pointer to that memory. For example:struct type_SNMP_SMUX__PDUs *event;smux_wait(&event, NOTOK);After smux_wait() returns, the contents of the *event structure can be examined and processed.
Note, however, that it is up to the calling program to free up the
memory that smux_wait() allocated once it is done being processed.
The foosmuxd program fails to do that, and thus "loses track" of
the allocated memory. Each time smux_wait() gets called, more
memory gets allocated. Solution
Edit foosmuxd.c as indicated below. At the very end of the function
doit_smux(), add a call to free_SNMP_SMUX_PDU(event).static
doit_smux()
{/* . . . body of doit_smux() . . . */
default:
LIB_ERROR1("badOperation: %d", event->offset);
(void) smux_close(protocolError);
goto losing;
}
[add this]
> /*
> * smux_wait() allocated a PDU for us -- we must free it,
> * lest we leak.
> */
> free_SNMP_SMUX_PDU(event);
}/* end of doit_smux() * * */Other programs that were developed using foosmuxd.c should also be
examined. Each time smux_wait() is called, the "event" pointer it
returns must later be passed to free_SNMP_SMUX_PDU() to avoid memory
leaks.This problem has been reported to SCO Engineering.