diff --git a/vvp/class_type.cc b/vvp/class_type.cc index 6770e6715..2b925b64a 100644 --- a/vvp/class_type.cc +++ b/vvp/class_type.cc @@ -47,7 +47,7 @@ void compile_class_start(char*lab, char*nam, unsigned ntype) assert(compile_class == 0); compile_class = new class_type(nam, ntype); compile_vpi_symbol(lab, compile_class); - delete[]lab; + free(lab); delete[]nam; } @@ -64,4 +64,3 @@ void compile_class_done(void) scope->classes[compile_class->class_name()] = compile_class; compile_class = 0; } - diff --git a/vvp/codes.cc b/vvp/codes.cc index 1f2ab1ad6..7f08077f9 100644 --- a/vvp/codes.cc +++ b/vvp/codes.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2011 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2012 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -117,6 +117,10 @@ void codespace_delete(void) exec_ufunc_delete((cur+idx)); } else if ((cur+idx)->opcode == &of_FILE_LINE) { delete((cur+idx)->handle); + } else if (((cur+idx)->opcode == &of_CONCATI_STR) || + ((cur+idx)->opcode == &of_NEW_DARRAY) || + ((cur+idx)->opcode == &of_PUSHI_STR)) { + delete [] ((cur+idx)->text); } if (count_opcodes == 0) break; } diff --git a/vvp/main.cc b/vvp/main.cc index 362044724..323835fa2 100644 --- a/vvp/main.cc +++ b/vvp/main.cc @@ -218,6 +218,7 @@ static void final_cleanup() dec_str_delete(); modpath_delete(); vpi_handle_delete(); + vpi_stack_delete(); udp_defns_delete(); island_delete(); signal_pool_delete(); diff --git a/vvp/vpi_cobject.cc b/vvp/vpi_cobject.cc index c406573ed..ca78c3ff9 100644 --- a/vvp/vpi_cobject.cc +++ b/vvp/vpi_cobject.cc @@ -20,6 +20,10 @@ # include "compile.h" # include "vpi_priv.h" +# include "config.h" +#ifdef CHECK_WITH_VALGRIND +# include "vvp_cleanup.h" +#endif __vpiCobjectVar::__vpiCobjectVar(__vpiScope*sc, const char*na, vvp_net_t*ne) : __vpiBaseVar(sc, na, ne) @@ -48,3 +52,11 @@ vpiHandle vpip_make_cobject_var(const char*name, vvp_net_t*net) return obj; } + +#ifdef CHECK_WITH_VALGRIND +void class_delete(vpiHandle item) +{ + class __vpiCobjectVar*obj = dynamic_cast<__vpiCobjectVar*>(item); + delete obj; +} +#endif diff --git a/vvp/vpi_darray.cc b/vvp/vpi_darray.cc index 9a6336a8b..f6fb39d4a 100644 --- a/vvp/vpi_darray.cc +++ b/vvp/vpi_darray.cc @@ -76,3 +76,11 @@ vpiHandle vpip_make_darray_var(const char*name, vvp_net_t*net) return obj; } + +#ifdef CHECK_WITH_VALGRIND +void darray_delete(vpiHandle item) +{ + class __vpiDarrayVar*obj = dynamic_cast<__vpiDarrayVar*>(item); + delete obj; +} +#endif diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index a22343852..e21984b38 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -60,10 +60,11 @@ extern vpiHandle vpip_build_file_line(char*description, #ifdef CHECK_WITH_VALGRIND #define _vpiFromThr 0x1000001 # define _vpiNoThr 0 -# define _vpiVThr 1 -# define _vpiWord 2 -# define _vpi_at_PV 3 -# define _vpi_at_A 4 +# define _vpiString 1 +# define _vpiVThr 2 +# define _vpiWord 3 +# define _vpi_at_PV 4 +# define _vpi_at_A 5 #endif diff --git a/vvp/vpi_scope.cc b/vvp/vpi_scope.cc index dab4ab5af..a2b5d5976 100644 --- a/vvp/vpi_scope.cc +++ b/vvp/vpi_scope.cc @@ -100,7 +100,13 @@ static void delete_sub_scopes(struct __vpiScope *scope) port_delete((scope->intern)[idx]); break; case vpiStringVar: + string_delete((scope->intern)[idx]); + break; + case vpiClassVar: + class_delete((scope->intern)[idx]); + break; case vpiRegArray: + darray_delete((scope->intern)[idx]); break; default: fprintf(stderr, "Need support for type: %d\n", diff --git a/vvp/vpi_string.cc b/vvp/vpi_string.cc index c2158850b..6a1bd10d4 100644 --- a/vvp/vpi_string.cc +++ b/vvp/vpi_string.cc @@ -82,3 +82,11 @@ vpiHandle vpip_make_string_var(const char*name, vvp_net_t*net) return obj; } + +#ifdef CHECK_WITH_VALGRIND +void string_delete(vpiHandle item) +{ + class __vpiStringVar*obj = dynamic_cast<__vpiStringVar*>(item); + delete obj; +} +#endif diff --git a/vvp/vpi_tasks.cc b/vvp/vpi_tasks.cc index 3dc2fda3d..06617b965 100644 --- a/vvp/vpi_tasks.cc +++ b/vvp/vpi_tasks.cc @@ -843,6 +843,9 @@ void vpi_call_delete(vpiHandle item) case _vpiNoThr: constant_delete(obj->args[arg]); break; + case _vpiString: + thread_string_delete(obj->args[arg]); + break; case _vpiVThr: thread_vthr_delete(obj->args[arg]); break; diff --git a/vvp/vpi_vthr_vector.cc b/vvp/vpi_vthr_vector.cc index 27f8f5158..335510e5e 100644 --- a/vvp/vpi_vthr_vector.cc +++ b/vvp/vpi_vthr_vector.cc @@ -660,6 +660,10 @@ int __vpiVThrStrStack::vpi_get(int code) switch (code) { case vpiConstType: return vpiStringConst; +#ifdef CHECK_WITH_VALGRIND + case _vpiFromThr: + return _vpiString; +#endif default: return 0; } @@ -698,3 +702,26 @@ vpiHandle vpip_make_vthr_str_stack(unsigned depth) class __vpiVThrStrStack*obj = new __vpiVThrStrStack(depth); return obj; } + +#ifdef CHECK_WITH_VALGRIND +static map stack_map; + +void thread_string_delete(vpiHandle item) +{ + stack_map[item] = false; +} + +static void thread_string_delete_real(vpiHandle item) +{ + class __vpiVThrStrStack*obj = dynamic_cast<__vpiVThrStrStack*>(item); + delete obj; +} + +void vpi_stack_delete() +{ + map::iterator iter; + for (iter = stack_map.begin(); iter != stack_map.end(); ++ iter ) { + thread_string_delete_real(iter->first); + } +} +#endif diff --git a/vvp/vvp_cleanup.h b/vvp/vvp_cleanup.h index ca851d2ef..66ddc57ae 100644 --- a/vvp/vvp_cleanup.h +++ b/vvp/vvp_cleanup.h @@ -36,19 +36,24 @@ extern void root_table_delete(void); extern void signal_pool_delete(void); extern void udp_defns_delete(void); extern void vpi_handle_delete(void); +extern void vpi_stack_delete(void); extern void vvp_net_pool_delete(void); extern void ufunc_pool_delete(void); extern void A_delete(class __vpiHandle *item); extern void PV_delete(class __vpiHandle *item); +extern void class_delete(class __vpiHandle *item); extern void constant_delete(class __vpiHandle *item); extern void contexts_delete(struct __vpiScope *scope); +extern void darray_delete(class __vpiHandle *item); extern void enum_delete(class __vpiHandle *item); extern void memory_delete(class __vpiHandle *item); extern void named_event_delete(class __vpiHandle *item); extern void parameter_delete(class __vpiHandle *item); extern void signal_delete(class __vpiHandle *item); extern void real_delete(class __vpiHandle *item); +extern void string_delete(class __vpiHandle *item); +extern void thread_string_delete(class __vpiHandle *item); extern void thread_vthr_delete(class __vpiHandle *item); extern void thread_word_delete(class __vpiHandle *item); extern void vpi_call_delete(class __vpiHandle *item);