From 743eb48856ae025308892f69e3849cb3d32113b4 Mon Sep 17 00:00:00 2001 From: kris Date: Mon, 9 Jun 2008 16:54:08 +0000 Subject: [PATCH] o Fixed some memory leaks in NSE found with Valgrind. [Kris] --- CHANGELOG | 2 ++ Target.cc | 7 ++++++- nse_main.cc | 13 +++++++++++++ portlist.cc | 5 +++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a2ecaa739..c2e4d4beb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -20,6 +20,8 @@ o Fixed an integer overflow which prevented a target specification of "*.*.*.*" from working. Support for the CIDR /0 is now also available. [Kris] +o Fixed some memory leaks in NSE found with Valgrind. [Kris] + o Nmap now returns correct values for --iflist in windows even if interface aliases have been set. Previously it would misreport the windevices and not list all interfaces. [Michael] diff --git a/Target.cc b/Target.cc index 871cb0e9d..f0bede996 100644 --- a/Target.cc +++ b/Target.cc @@ -165,7 +165,6 @@ Target::~Target() { } void Target::FreeInternal() { - /* Free the DNS name if we resolved one */ if (hostname) free(hostname); @@ -179,6 +178,12 @@ void Target::FreeInternal() { } if (FPR) delete FPR; + + if (o.script) { + ScriptResults::iterator sriter; + for (sriter = scriptResults.begin(); sriter != scriptResults.end(); sriter++) + free((*sriter).id); + } } /* Creates a "presentation" formatted string out of the IPv4/IPv6 address. diff --git a/nse_main.cc b/nse_main.cc index c6b4435cc..47522436c 100644 --- a/nse_main.cc +++ b/nse_main.cc @@ -70,6 +70,9 @@ int process_mainloop(lua_State* L); int process_waiting2running(lua_State* L, int resume_arguments); int process_finalize(lua_State* L, unsigned int registry_idx); +// post execution +int cleanup_threads(std::list trs); + static int panic (lua_State *L) { const char *err = lua_tostring(L, 1); @@ -298,6 +301,7 @@ finishup: log_write(LOG_STDOUT, "%s: Script scanning completed.\n", SCRIPT_ENGINE); ) lua_close(L); + cleanup_threads(torun_threads); torun_scripts.clear(); if(status != SCRIPT_ENGINE_SUCCESS) { error("%s: Aborting script scan.", SCRIPT_ENGINE); @@ -751,4 +755,13 @@ int process_preparethread(lua_State* L, struct run_record rr, struct thread_reco return SCRIPT_ENGINE_SUCCESS; } +int cleanup_threads(std::list trs) +{ + std::list::iterator triter; + + for (triter = trs.begin(); triter != trs.end(); triter++) + free((*triter).rr); + + return SCRIPT_ENGINE_SUCCESS; +} diff --git a/portlist.cc b/portlist.cc index 1be4efcc6..25546b091 100644 --- a/portlist.cc +++ b/portlist.cc @@ -150,6 +150,11 @@ Port::~Port() { free(serviceprobe_service); if (serviceprobe_fp) free(serviceprobe_fp); + if (o.script) { + ScriptResults::iterator sriter; + for (sriter = scriptResults.begin(); sriter != scriptResults.end(); sriter++) + free((*sriter).id); + } } // Uses the sd->{product,version,extrainfo} if available to fill