Forum OpenACS Q&A: Response to Call Doctor or Plumber? : Memory Leak

Collapse
Posted by Jerry Asher on
I don't know "where" it should be called. I know what I did.

I created a routine nsd/conn.c/Ns_ConnFree to call the underlying driver freeProc (if it exists)

/*
 *-----------------------------------------------------------------
 *
 * Ns_ConnFree - Free a connection.
 *
 * Results:
 *	Always NS_OK.
 * 
 * Side effects:
 *	The underlying driver connection buffers are freed
 *
 *-----------------------------------------------------------------
 */

int
Ns_ConnFree(Ns_Conn *conn)
{
    Conn             *connPtr = (Conn *)conn;
    
    if (connPtr->drvPtr->freeProc != NULL) {
        (*connPtr->drvPtr->freeProc)(connPtr->drvData);
    }
    return NS_OK;
}

I then call this function in two places: first, at the very end of nsd/serv.c/ConnRun (just prior to freeing the DString).
. . .
    Ns_ConnFree(conn);
    Ns_DStringFree(&ds);
}
And also within nsd/drv.c/RunDriver if there is a problem queueing a connection with Ns_QueueConn:
    while ((status = ((*dPtr->acceptProc)(dData, &cData))) == NS_OK) {
	/* Bug fix note: Call with dPtr and not dData
	   I know this is right for nsunix,
	   and it would be right for nssock and nsssl except
	   that nssock and nsssl do not use THIS procedure.
	   Are there any other modules that need to be looked at? */
	if (Ns_QueueConn(dPtr, cData) != NS_OK) {
            /* Bug fix note: now call with cData and not dData! */
            // (*dPtr->closeProc)(dData);
            (*dPtr->closeProc)(cData);
            /*
             * let the driver free connection structures
             */
            if (dPtr->freeProc != NULL) {
                (*dPtr->freeProc)(cData);
            }
	}
    }
Of course, my patches incorporate this and lots lots more. Act now! Supplies are limited!