diff --git a/nmap.cc b/nmap.cc index 21d593086..2cdb35a6e 100644 --- a/nmap.cc +++ b/nmap.cc @@ -1993,6 +1993,7 @@ void nmap_free_mem() { cp_free(); free_dns_servers(); free_etchosts(); + free_services(); if (o.reference_FPs) { delete o.reference_FPs; o.reference_FPs = NULL; diff --git a/services.cc b/services.cc index 6b4706a9c..4dd77ab72 100644 --- a/services.cc +++ b/services.cc @@ -129,13 +129,13 @@ bool service_node_ratio_compare(const service_node& a, const service_node& b) { } extern NmapOps o; -static int numtcpports = 0; -static int numudpports = 0; -static int numsctpports = 0; +static int numtcpports; +static int numudpports; +static int numsctpports; static std::map service_table; static std::list services_by_ratio; -static int services_initialized = 0; -static int ratio_format = 0; // 0 = /etc/services no-ratio format. 1 = new nmap format +static int services_initialized; +static int ratio_format; // 0 = /etc/services no-ratio format. 1 = new nmap format static int nmap_services_init() { if (services_initialized) return 0; @@ -152,6 +152,13 @@ static int nmap_services_init() { int ratio_n, ratio_d; char ratio_str[32]; + numtcpports = 0; + numudpports = 0; + numsctpports = 0; + service_table.clear(); + services_by_ratio.clear(); + ratio_format = 0; + if (nmap_fetchfile(filename, sizeof(filename), "nmap-services") != 1) { #ifndef WIN32 error("Unable to find nmap-services! Resorting to /etc/services"); @@ -277,6 +284,13 @@ static int nmap_services_init() { return 0; } +void free_services() { + /* This doesn't free anything, because the service_table is allocated + statically. It just marks the table as needing to be reinitialized because + other things have been freed, for example the cp_strdup-allocated members + of service_node. */ + services_initialized = 0; +} /* Adds ports whose names match mask and one or more protocols diff --git a/services.h b/services.h index 62366bb7a..4713a525a 100644 --- a/services.h +++ b/services.h @@ -118,4 +118,6 @@ int addportsfromservmask(char *mask, u8 *porttbl, int range_type); struct servent *nmap_getservbyport(int port, const char *proto); void gettoppts(double level, char *portlist, struct scan_lists * ports); +void free_services(); + #endif