Hi,
This is a revised version of the patch with Burton's suggestion and some extra cleanup
(removed variable).
Description: In a previous patch to introduce graceful handling of OOM in RRDplugin's
domainstats routine, I introduced a possible memory leak. The only situation in which
this would occur is when the box was OOM anyway, but that shouldn't keep ntop from
freeing unused memory.
Robbert
--- ntop/plugins/rrdPlugin.c.orig 2004-06-24 14:11:09.902811680 +0200
+++ ntop/plugins/rrdPlugin.c 2004-06-24 15:36:24.288306904 +0200
@@ -1852,7 +1852,7 @@
if(dumpDomains) {
DomainStats **stats, *tmpStats, *statsEntry;
- u_int maxHosts, len = 0;
+ u_int maxHosts = 0;
Counter totBytesSent = 0;
Counter totBytesRcvd = 0;
HostTraffic *el;
@@ -1863,18 +1863,19 @@
/* save this as it may change */
maxHosts = myGlobals.device[devIdx].hostsno;
- len = sizeof(DomainStats)*maxHosts;
- tmpStats = (DomainStats*)mallocAndInitWithReportWarn(len, "rrdMainLoop");
+ tmpStats = (DomainStats*)mallocAndInitWithReportWarn(maxHosts*sizeof(DomainStats),
"rrdMainLoop");
+
if (tmpStats == NULL) {
traceEvent(CONST_TRACE_WARNING, "RRD: Out of memory, skipping domain RRD
dumps");
continue;
}
- len = sizeof(DomainStats**)*maxHosts;
- stats = (DomainStats**)mallocAndInitWithReportWarn(len, "rrdMainLoop(2)");
+ stats =
(DomainStats**)mallocAndInitWithReportWarn(maxHosts*sizeof(DomainStats*),"rrdMainLoop(2)");
if (stats == NULL) {
- traceEvent(CONST_TRACE_WARNING, "RRD: Out of memory, skipping domain RRD
dumps");
+ traceEvent(CONST_TRACE_WARNING, "RRD: Out of memory, skipping domain RRD dumps");
+ /* before continuing, also free the block of memory allocated a few lines up */
+ if (tmpStats != NULL) free(tmpStats);
continue;
}
rrdplugin-free-memory-fix-2.diff
Description: rrdplugin-free-memory-fix-2.diff
_______________________________________________ Ntop-dev mailing list [EMAIL PROTECTED] http://listgateway.unipi.it/mailman/listinfo/ntop-dev
