Remove some valgrind warnings and a few errors

Cleanup a few more of the new constructs and fix free/delete mismatches.
This commit is contained in:
Cary R 2012-12-18 11:08:30 -08:00
parent 317e53e784
commit 3fa7b3f05a
11 changed files with 81 additions and 7 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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();

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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",

View File

@ -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

View File

@ -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;

View File

@ -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<vpiHandle, bool> 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<vpiHandle, bool>::iterator iter;
for (iter = stack_map.begin(); iter != stack_map.end(); ++ iter ) {
thread_string_delete_real(iter->first);
}
}
#endif

View File

@ -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);