Clean up some more memory when using valgrind

When checking with valgrind clean up the following:

  The arguments for invalid task/function calls.

  The simulation callback queues (only needed when the runtime aborts).

  Call pthread_exit(NULL) just before exiting to cleanup dynamic loading.
This commit is contained in:
Cary R 2013-01-03 17:49:29 -08:00
parent 1305d7659c
commit f682d9cad1
4 changed files with 51 additions and 6 deletions

View File

@ -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
@ -31,6 +31,9 @@
# include <cstdlib>
# include <cstring>
# include <unistd.h>
#ifdef CHECK_WITH_VALGRIND
# include <pthread.h>
#endif
#if defined(HAVE_SYS_RESOURCE_H)
# include <sys/time.h>
@ -232,6 +235,14 @@ static void final_cleanup()
* files are automatically closed.
*/
load_module_delete();
#ifdef CHECK_WITH_VALGRIND
simulator_cb_delete();
/* This is needed to prevent valgrind from complaining about
* _dlerror_run() having a memory leak. */
// HERE: Is this portable? Does it break anything?
pthread_exit(NULL);
#endif
}
unsigned module_cnt = 0;

View File

@ -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
@ -31,6 +31,9 @@
# include "event.h"
# include "vvp_net_sig.h"
# include "config.h"
#ifdef CHECK_WITH_VALGRIND
#include "vvp_cleanup.h"
#endif
# include <cstdio>
# include <cassert>
# include <cstdlib>
@ -412,6 +415,36 @@ static simulator_callback*EndOfCompile = 0;
static simulator_callback*StartOfSimulation = 0;
static simulator_callback*EndOfSimulation = 0;
#ifdef CHECK_WITH_VALGRIND
/* This is really only needed if the simulator aborts before starting the
* main event loop. For that reason we can skip the next sim time queue. */
void simulator_cb_delete(void)
{
simulator_callback* cur;
/* Delete all the end of compile callbacks. */
while (EndOfCompile) {
cur = EndOfCompile;
EndOfCompile = dynamic_cast<simulator_callback*>(cur->next);
delete cur;
}
/* Delete all the start of simulation callbacks. */
while (StartOfSimulation) {
cur = StartOfSimulation;
StartOfSimulation = dynamic_cast<simulator_callback*>(cur->next);
delete cur;
}
/* Delete all the end of simulation callbacks. */
while (EndOfSimulation) {
cur = EndOfSimulation;
EndOfSimulation = dynamic_cast<simulator_callback*>(cur->next);
delete cur;
}
}
#endif
void vpiEndOfCompile(void) {
simulator_callback* cur;

View File

@ -706,14 +706,14 @@ void print_vpi_call_errors()
#ifdef CHECK_WITH_VALGRIND
static void cleanup_vpi_call_args(unsigned argc, vpiHandle*argv)
{
#if 0
if (argc) {
struct __vpiSysTaskCall*obj = new struct __vpiSysTaskCall;
/* Since this is just being used to cleanup the arguments a
* system task definition can be used. */
struct __vpiSysTaskCall*obj = new systask_def;
obj->nargs = argc;
obj->args = argv;
vpi_call_delete(&obj->base);
vpi_call_delete(obj);
}
#endif
}
#endif

View File

@ -34,6 +34,7 @@ extern void load_module_delete(void);
extern void modpath_delete(void);
extern void root_table_delete(void);
extern void signal_pool_delete(void);
extern void simulator_cb_delete(void);
extern void udp_defns_delete(void);
extern void vpi_handle_delete(void);
extern void vpi_stack_delete(void);