I am trying to use an sc_vector of modules with a custom creator to pass constructor arguments. It seems to work and run through the entire program, but at exit causes a segfault. GDB shows that this is due to to sc_vector calling the destructor of the module.
I have no dynamically-allocated memory or pointers in the module. Here's the overview:
outside of sc_main (global -- but I also tried inside of sc_main):
--------------------------
struct create_mod { unsigned int m_arg1; unsigned int m_arg2; create_mod(unsigned int arg1, unsigned int arg2) : m_arg1(arg1), m_arg2(arg2) {} mod* operator()(const char* name, size_t) { return new mod(name, m_arg1, m_arg2); } };
Inside sc_main:
---------------------------
unsigned int num_of_mods = 8; unsigned int args1 = 5, args2 = 4; sc_vector<mod> vec_mod("mods"); vec_mod.init(num_of_mods, create_mod(args1, args2)); // ... use vec_mod, bind ports, etc ... return 0;
So the program runs, then segfaults at the end with "core dumped". GDB results:
Program received signal SIGSEGV, Segmentation fault.
__GI___libc_free (mem=0x5006e4b8e) at malloc.c:2929
2929 malloc.c: No such file or directory.
Backtracing shows:
#0 __GI___libc_free (mem=0x5006e4b8e) at malloc.c:2929
#1 0x00007ffff77e017b in sc_core::sc_module::~sc_module() ()
from /usr/local/systemc/lib-linux64/libsystemc-2.3.1.so
#2 0x000000000042e6a0 in mod::~mod (this=0x6bf650) at ../src/mod.h:25
#3 0x000000000042e6c9 in mod::~mod (this=0x6bf650) at ../src/mod.h:25
#4 0x000000000044593b in sc_core::sc_vector<mod>::clear (this=0x7fffffffc748)
at /usr/local/systemc/include/sysc/utils/sc_vector.h:653
#5 0x0000000000442e6f in sc_core::sc_vector<mod>::~sc_vector (
this=0x7fffffffc748)
at /usr/local/systemc/include/sysc/utils/sc_vector.h:696
#6 0x0000000000441fb4 in sc_main (sc_argc=1, sc_argv=0x6a8400)
at ../src/main.cpp:334
#7 0x00007ffff77dd674 in sc_elab_and_sim ()
from /usr/local/systemc/lib-linux64/libsystemc-2.3.1.so
#8 0x00007ffff6e9fec5 in __libc_start_main (main=0x404b00 <main@plt>, argc=1,
argv=0x7fffffffdf48, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7fffffffdf38) at libc-start.c:287
#9 0x0000000000406a5c in _start ()
Note the bit in red. Also note that line 334 is the closing brace of sc_main.
Also:
(gdb) frame 2
#2 0x000000000042e6a0 in mod::~mod (this=0x6bf650) at ../src/mod.h:25
25 class mod : public sc_module
(gdb) frame 3
#3 0x000000000042e6c9 in mod::~mod (this=0x6bf650) at ../src/mod.h:25
25 class mod : public sc_module
As I said, I have no dynamically-allocated memory in the class. I have tried an empty destructor (as well as = default since I'm using C++11) but got the same result.
Any ideas?
Thanks in advance.