From 927edf03d6e30334876f8d727b2d0c40625f3d30 Mon Sep 17 00:00:00 2001 From: Cary R Date: Wed, 2 Jan 2013 16:59:04 -0800 Subject: [PATCH 1/3] Clean up SV class definition when using valgrind. Also fix a memory leak when compiling class properties. --- vvp/class_type.cc | 15 ++++++++++++++- vvp/vpi_scope.cc | 10 +++++++++- vvp/vvp_cleanup.h | 2 ++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/vvp/class_type.cc b/vvp/class_type.cc index 2b925b64a..9606d4ca2 100644 --- a/vvp/class_type.cc +++ b/vvp/class_type.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Stephen Williams (steve@icarus.com) + * Copyright (c) 2012-2013 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 @@ -20,6 +20,10 @@ # include "class_type.h" # include "compile.h" # include "vpi_priv.h" +# include "config.h" +#ifdef CHECK_WITH_VALGRIND +# include "vvp_cleanup.h" +#endif # include using namespace std; @@ -55,6 +59,8 @@ void compile_class_property(unsigned idx, char*nam, char*typ) { assert(compile_class); compile_class->set_property(idx, nam); + delete[]nam; + delete[]typ; } void compile_class_done(void) @@ -64,3 +70,10 @@ void compile_class_done(void) scope->classes[compile_class->class_name()] = compile_class; compile_class = 0; } + +#ifdef CHECK_WITH_VALGRIND +void class_def_delete(class_type *item) +{ + delete item; +} +#endif diff --git a/vvp/vpi_scope.cc b/vvp/vpi_scope.cc index a2b5d5976..3fa5ff52d 100644 --- a/vvp/vpi_scope.cc +++ b/vvp/vpi_scope.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2012 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2013 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 @@ -116,6 +116,14 @@ static void delete_sub_scopes(struct __vpiScope *scope) } } free(scope->intern); + + /* Clean up any class definitions. */ + map::iterator citer; + for (citer = scope->classes.begin(); + citer != scope->classes.end(); ++ citer ) { + class_def_delete(citer->second); + } + scope->classes.clear(); } void root_table_delete(void) diff --git a/vvp/vvp_cleanup.h b/vvp/vvp_cleanup.h index 7f4237643..c5de97967 100644 --- a/vvp/vvp_cleanup.h +++ b/vvp/vvp_cleanup.h @@ -44,6 +44,7 @@ extern void A_delete(class __vpiHandle *item); extern void APV_delete(class __vpiHandle *item); extern void PV_delete(class __vpiHandle *item); extern void class_delete(class __vpiHandle *item); +extern void class_def_delete(class_type *item); extern void constant_delete(class __vpiHandle *item); extern void contexts_delete(struct __vpiScope *scope); extern void darray_delete(class __vpiHandle *item); @@ -62,6 +63,7 @@ extern void exec_ufunc_delete(vvp_code_t euf_code); extern void vthreads_delete(struct __vpiScope*scope); extern void vvp_net_delete(vvp_net_t *item); + extern void pool_local_net(vvp_net_t *net); #endif From 4407bc1d500442feec11119e8ff1cf0355559c77 Mon Sep 17 00:00:00 2001 From: Cary R Date: Wed, 2 Jan 2013 18:30:59 -0800 Subject: [PATCH 2/3] Fix memory leak when displaying a SV string variable. --- vpi/sys_display.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vpi/sys_display.c b/vpi/sys_display.c index 9151051d9..5ed2000ac 100644 --- a/vpi/sys_display.c +++ b/vpi/sys_display.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2012 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2013 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 @@ -974,6 +974,7 @@ static char *get_display(unsigned int *rtnsz, const struct strobe_cb_info *info) free(fmt); rtn = realloc(rtn, (size+width)*sizeof(char)); memcpy(rtn+size-1, result, width); + free(result); break; case vpiSysFuncCall: From 10b5a829047f5b3162721d7616ed65923fc3851c Mon Sep 17 00:00:00 2001 From: Cary R Date: Wed, 2 Jan 2013 19:17:58 -0800 Subject: [PATCH 3/3] Remove redundent map clear. --- vvp/vpi_scope.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/vvp/vpi_scope.cc b/vvp/vpi_scope.cc index 3fa5ff52d..072839a03 100644 --- a/vvp/vpi_scope.cc +++ b/vvp/vpi_scope.cc @@ -123,7 +123,6 @@ static void delete_sub_scopes(struct __vpiScope *scope) citer != scope->classes.end(); ++ citer ) { class_def_delete(citer->second); } - scope->classes.clear(); } void root_table_delete(void)