P
Piotr
I have a class 'Statistics' which has a private attribute
' vector<int>* _x;'
And in the destructor of the Statistics, I have this code to free the
memory:
Statistics::~Statistics()
{
if (_x) {
delete _x; // Seg fault here...
}
}
But I get a Seg. Fault when I execute the program.
Can you please tell me what did I do wrong?
Thank you.
(gdb) bt
#0 0x00248eaa in __gnu_cxx::__pool<true>::_M_reclaim_block () from
/usr/lib/libstdc++.so.6
#1 0x0250da84 in __gnu_cxx::__mt_alloc<int,
__gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, true> >::deallocate
(this=0x9107474, __p=0xdadadada, __n=152471256) at mt_allocator.h:746
#3 0x0250dacd in ~_Vector_base (this=0x91686d8) at stl_vector.h:109
#4 0x0250db0b in ~vector (this=0x9107474) at stl_vector.h:273
#5 0x0250caf2 in ~Statistics (this=0xbfd85ad8) at
Statistics.cpp:54
' vector<int>* _x;'
And in the destructor of the Statistics, I have this code to free the
memory:
Statistics::~Statistics()
{
if (_x) {
delete _x; // Seg fault here...
}
}
But I get a Seg. Fault when I execute the program.
Can you please tell me what did I do wrong?
Thank you.
(gdb) bt
#0 0x00248eaa in __gnu_cxx::__pool<true>::_M_reclaim_block () from
/usr/lib/libstdc++.so.6
#1 0x0250da84 in __gnu_cxx::__mt_alloc<int,
__gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, true> >::deallocate
(this=0x9107474, __p=0xdadadada, __n=152471256) at mt_allocator.h:746
stl_vector.h:123#2 0x0250daac in std::_Vector_base said:::_M_deallocate (this=0x9107474, __p=0x91686d8, __n=0) at
#3 0x0250dacd in ~_Vector_base (this=0x91686d8) at stl_vector.h:109
#4 0x0250db0b in ~vector (this=0x9107474) at stl_vector.h:273
#5 0x0250caf2 in ~Statistics (this=0xbfd85ad8) at
Statistics.cpp:54