rem: dataPtr->connPtr = NULL;
add: Ns_MutexLock(&poolPtr->lock);
context: NsConnThread(void *arg){    ConnThreadData  *dataPtr = arg;    Pool            *poolPtr = dataPtr->poolPtr;    Conn            *connPtr;    Ns_Time          wait, *timePtr;    char             name[100];    int              status, ncons;    char            *msg;        /*     * Set the conn thread name.     */    Ns_TlsSet(&ctdtls, dataPtr);    Ns_MutexLock(&poolPtr->lock);    sprintf(name, "-conn:%d-", poolPtr->threads.nextid++);    Ns_MutexUnlock(&poolPtr->lock);    Ns_ThreadSetName(name);    ncons = poolPtr->threads.maxconns;    msg = "exceeded max connections per thread";        /*     * Start handling connections.     */    Ns_MutexLock(&poolPtr->lock);    while (poolPtr->threads.maxconns <= 0 || ncons-- > 0) {	/*	 * Wait for a connection to arrive, exiting if one doesn't	 * arrive in the configured timeout period.	 */	if (poolPtr->threads.current <= poolPtr->threads.min) {	    timePtr = NULL;	} else {	    Ns_GetTime(&wait);	    Ns_IncrTime(&wait, poolPtr->threads.timeout, 0);	    timePtr = &wait;	}	status = NS_OK;        while (!poolPtr->shutdown		&& status == NS_OK                && poolPtr->queue.wait.firstPtr == NULL) {            status = Ns_CondTimedWait(&poolPtr->cond, &poolPtr->lock, timePtr);	}	if (poolPtr->queue.wait.firstPtr == NULL) {	    msg = "timeout waiting for connection";	    break;	}	/*	 * Pull the first connection off the waiting list.	 */    	connPtr = poolPtr->queue.wait.firstPtr;    	poolPtr->queue.wait.firstPtr = connPtr->nextPtr;     	if (poolPtr->queue.wait.lastPtr == connPtr) {	    poolPtr->queue.wait.lastPtr = NULL;    	}	connPtr->nextPtr = NULL;	connPtr->prevPtr = poolPtr->queue.active.lastPtr;	if (poolPtr->queue.active.lastPtr != NULL) {	    poolPtr->queue.active.lastPtr->nextPtr = connPtr;	}	poolPtr->queue.active.lastPtr = connPtr;	if (poolPtr->queue.active.firstPtr == NULL) {	    poolPtr->queue.active.firstPtr = connPtr;	}	poolPtr->threads.idle--;	poolPtr->queue.wait.num--;        dataPtr->connPtr = connPtr;	/*	 * Run the connection.	 */        Ns_MutexUnlock(&poolPtr->lock);	Ns_GetTime(&connPtr->times.run);        ConnRun(connPtr);        Ns_MutexLock(&poolPtr->lock);	/*	 * Remove from the active list and push on the free list.	 */        dataPtr->connPtr = NULL;	if (connPtr->prevPtr != NULL) {	    connPtr->prevPtr->nextPtr = connPtr->nextPtr;	} else {	    poolPtr->queue.active.firstPtr = connPtr->nextPtr;	}	if (connPtr->nextPtr != NULL) {	    connPtr->nextPtr->prevPtr = connPtr->prevPtr;	} else {	    poolPtr->queue.active.lastPtr = connPtr->prevPtr;	}	poolPtr->threads.idle++;        Ns_MutexUnlock(&poolPtr->lock);        NsFreeConn(connPtr);        Ns_MutexLock(&poolPtr->lock);    }    poolPtr->threads.idle--;    poolPtr->threads.current--;    if (poolPtr->threads.current == 0) {        Ns_CondBroadcast(&poolPtr->cond);    }    if (poolPtr->shutdown) {	msg = "shutdown pending";    }    Ns_Log(Notice, "exiting: %s", msg);    Ns_MutexUnlock(&poolPtr->lock);    Ns_ThreadExit(dataPtr);}