Technical article 107674

SMUX program (such as example 'foosmuxd') has a "memory leak".

OpenServer 5.0.0OpenServer 5.0.2

Written · Last revised

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.

From the Xinuos technical article database, record 107674. Reproduced with permission. The original is at www.sco.com/ta/107674, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.