SNMP++ Version: 3.4.2
Agent++ Version: 4.3.1
I am investigating a series of application crashes occurring in our Agent running Agent++.
The agent has a recurring timer that spawns a thread every 10 seconds. The thread first queries the load on each CPU and then uses those CPU load values to update the host_resources_mib_hrProcessorEntry MibTable via the set_row function (which then calls MibLeaf::replace_value).
Do you have any suggestions on steps to further investigate these crashes?
Are there any code changes you would suggest we make in how the MibTable is updated or how frequently it is being updated to possibly avoid these crashes?
Code Sample:
void CSnmpAgent::OnProcessorLoadUpdated(std::vector vCpuUtilizationPercentages)
{
MibTableRow* hrProcessorEntryMTR = nullptr;
//Loop through the CPU utilization percentages
for (size_t i = 0; i < vCpuUtilizationPercentages.size(); ++i)
{
int processorHrDeviceTableIndex = m_uHostResourcesDeviceTableProcessorStartIndex + i;
Agentpp::Oidx processorIndexOidx = Oidx() += std::to_string(processorHrDeviceTableIndex).c_str();
//Attempt to find an existing entry in the hrProcessorEntry mib table.
hrProcessorEntryMTR = host_resources_mib_hrProcessorEntry::instance->find_index(processorIndexOidx);
if (hrProcessorEntryMTR == 0)
{
hrProcessorEntryMTR = host_resources_mib_hrProcessorEntry::instance->add_row(processorIndexOidx);
}
**host_resources_mib_hrProcessorEntry::instance->set_row(hrProcessorEntryMTR, "0.0", int(round(vCpuUtilizationPercentages[i])));**
}
}
//From host_resources_mib.cpp obtained from AgenPro Code Samples for AGENT++ - SNMP Tools - AGENTPP
void host_resources_mib_hrProcessorEntry::set_row(MibTableRow* r, const char* p1, long p2)
{
r->get_nth(0)->replace_value(new NS_SNMP Oid(p1));
r->get_nth(1)->replace_value(new NS_SNMP SnmpInt32(p2));
}
Error Message: Unhandled exception at 0x773CFCDD (ntdll.dll) in SnmpAgent.exe.4968.dmp: 0xC0000374: A heap has been corrupted (parameters: 0x7740B960).
Crash Stack Trace:
ntdll.dll!_RtlReportFatalFailure@4()
ntdll.dll!_RtlReportCriticalFailure@12()
ntdll.dll!_RtlpReportHeapFailure@4()
ntdll.dll!_RtlpHpHeapHandleError@12()
ntdll.dll!_RtlpLogHeapFailure@24()
ntdll.dll!_RtlpFreeHeapInternal@20()
ntdll.dll!RtlFreeHeap()
ucrtbase.dll!_free_base()
ucrtbase.dll!_free()
[Inline Frame] Rescue21SnmpAgent.exe!Snmp_pp::Oid::delete_oid_ptr() Line 635
[Inline Frame] Rescue21SnmpAgent.exe!Snmp_pp::Oid::{dtor}() Line 175
[Inline Frame] Rescue21SnmpAgent.exe!Agentpp::Oidx::{dtor}() Line 95
SnmpAgent.exe!Agentpp::Oidx::`scalar deleting destructor’(unsigned int)
SnmpAgent.exe!Agentpp::MibLeaf::replace_value(Snmp_pp::SnmpSyntax * v) Line 230
SnmpAgent.exe!Agentpp::host_resources_mib_hrProcessorEntry::set_row(Agentpp::MibTableRow * r, const char * p1, long p2) Line 1801