From 196df151aaa497fca6a598322063b86d2ed85d17 Mon Sep 17 00:00:00 2001 From: Cary R Date: Wed, 4 Dec 2013 16:23:30 -0800 Subject: [PATCH] Correctly cleanup class and string object when using valgrind --- vvp/vpi_priv.cc | 10 ++++++++++ vvp/vpi_priv.h | 3 +++ vvp/vvp_net.cc | 10 +++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/vvp/vpi_priv.cc b/vvp/vpi_priv.cc index 15aff987e..4e020e43b 100644 --- a/vvp/vpi_priv.cc +++ b/vvp/vpi_priv.cc @@ -20,6 +20,9 @@ # include "version_base.h" # include "vpi_priv.h" # include "schedule.h" +#ifdef CHECK_WITH_VALGRIND +# include "vvp_cleanup.h" +#endif # include # include # include @@ -69,6 +72,13 @@ __vpiBaseVar::__vpiBaseVar(__vpiScope*scope, const char*name, vvp_net_t*net) { } +#ifdef CHECK_WITH_VALGRIND +__vpiBaseVar::~__vpiBaseVar() +{ + vvp_net_delete(net_); +} +#endif + /* * The default behavior for the vpi_free_object to an object is to * suppress the actual operation. This is because handles are diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index a547e71c3..bd0d743b5 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -487,6 +487,9 @@ class __vpiBaseVar : public __vpiHandle { public: __vpiBaseVar(__vpiScope*scope, const char*name, vvp_net_t*net); +#ifdef CHECK_WITH_VALGRIND + ~__vpiBaseVar(); +#endif inline vvp_net_t* get_net() const { return net_; } diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index 78b50145b..3e9f32695 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -111,9 +111,17 @@ void vvp_net_delete(vvp_net_t *item) if (vvp_udp_fun_core*tmp = dynamic_cast (item->fun)) { udp_map[tmp] = true; } - if (resolv_core*tmp = dynamic_cast(item->fun)) { + if (resolv_core*tmp = dynamic_cast (item->fun)) { resolv_map[tmp] = true; } + /* Only delete static object variables. */ + if (vvp_fun_signal_object_sa*tmp = dynamic_cast (item->fun)) { + delete tmp; + } + /* Only delete static string variables. */ + if (vvp_fun_signal_string_sa*tmp = dynamic_cast (item->fun)) { + delete tmp; + } } void vvp_net_pool_delete()