diff -ur --exclude=libipvs net-snmp-lvs-module-0.0.4/lvs.c net-snmp-lvs-module-0.0.4-leak_fix/lvs.c --- net-snmp-lvs-module-0.0.4/lvs.c 2006-01-02 14:31:54.000000000 +0000 +++ net-snmp-lvs-module-0.0.4-leak_fix/lvs.c 2010-05-19 15:15:14.000000000 +0100 @@ -37,6 +37,7 @@ static struct ip_vs_daemon_user* ipvs_daemon; static struct Destination* ipvs_destination; static time_t last_setup; +static struct ip_vs_get_dests** sentry_base = NULL; static void setup_snmp_ipvs(void) @@ -44,7 +45,7 @@ int s, d; struct Destination* mydestprev = NULL; struct Destination* mydest = ipvs_destination; - struct ip_vs_get_dests* sentry; + struct ip_vs_get_dests **sentry; time(&last_setup); if (ipvs_services) { @@ -64,22 +65,36 @@ ipvs_timeout = ipvs_get_timeouts(); #endif ipvs_daemon = ipvs_get_daemon(); + while (mydest) { mydestprev = mydest; mydest = mydest->next; SNMP_FREE(mydestprev); } mydestprev = NULL; + + /* NRC, 2010-05-18: Free old sentry structures... */ + sentry = sentry_base; + if (sentry) { + while (*sentry) { + free(*sentry); + sentry++; + } + free(sentry_base); + } + + sentry_base = calloc(ipvs_services->num_services + 1, sizeof(struct ip_vs_get_dests *)); for (s = 0; snum_services; s++) { - sentry = ipvs_get_dests(&ipvs_services->entrytable[s]); - for (d = 0; dnum_dests; d++) { + sentry = sentry_base + s; + *sentry = ipvs_get_dests(&ipvs_services->entrytable[s]); + for (d = 0; d < (*sentry)->num_dests; d++) { mydest = SNMP_MALLOC_STRUCT(Destination); if (mydestprev==NULL) { ipvs_destination = mydest; } else { mydestprev->next = mydest; } - mydest->dest_entry = &sentry->entrytable[d]; + mydest->dest_entry = &(*sentry)->entrytable[d]; mydest->svc_index = s+1; mydest->dst_index = d+1; mydest->next = NULL;