log redirection & memory leaks
Dave Barratt
dbarratt____codimatech.com
Mon Mar 31 21:34:34 CEST 2003
Hi,
I want to redirect the log to a file so I do the stuff below before anthing else in my 'main' - which works ok.
#ifndef _NO_LOGGING
//redirect logging to file
CString logPath = theApp.GetAppPath() + "\\snmp\\agentLog.txt";
log = new AgentLogImpl( logPath );
DefaultLog::init( log );
DefaultLog::log()->set_filter(ERROR_LOG, 5);
DefaultLog::log()->set_filter(WARNING_LOG, 5);
DefaultLog::log()->set_filter(EVENT_LOG, 5);
DefaultLog::log()->set_filter(INFO_LOG, 5);
DefaultLog::log()->set_filter(DEBUG_LOG, 6);
#endif
But when I come to cleanup when in my 'CSnmpAgent' class destructor using the code below I get access violation when the log is deleted - it appears snmp is still trying to use the log object in because ReleaseMutex is failing. I get alot of this message as a warning in the log during runtime.
void Synchronized::unlock() {
#ifdef POSIX_THREADS
pthread_mutex_unlock(&monitor);
#else
#ifdef WIN32
isLocked = FALSE;
if (!ReleaseMutex(semMutex)) {
LOG_BEGIN(WARNING_LOG | 1);
LOG("Synchronized: unlock failed");
LOG_END;
return;
}
#endif
#endif
}
void CSnmpAgent::cleanup()
{
if( mib )
delete mib;
mib = NULL;
if( reqList )
delete reqList;
reqList = NULL;
if( snmp )
delete snmp;
snmp = NULL;
if( log )
delete log;
log = NULL;
port = 0;
}
If I put a sleep() in after the if(log) this makes the code work but I don't think this is a good solution as sometimes this fails.
Another big problem is I get memory leaks from every newed mib object because the mib destructor doesn't delete the mibs that have been attached in the init method of my class. This code is just a copy of one of the examples at present.
What am I doing wrong?
Dave Barratt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.agentpp.org/pipermail/agentpp/attachments/20030331/fac35c29/attachment.htm
More information about the AGENTPP
mailing list