J
JDHawk
Hi,
when I compile my c++ program, MS Visual C++ (2003) shows this error:
Damage: after Normal Block (#139) at 0xXXXXXXXX
In Debug Mode I found out that it is the deallocation with "delete" in
the destructor.
When hiding the delete, there is no error, but I want to set my data
free in the destructor before the object dies. It has something to do
with the array that is allocated, cause a deletion of the ponter
"p_crc" works perfectly. Here the code: for explanation:
//send_frame is a struct with an pointer to uint8 as one element
//typedef signed char uint8;
//uint8* data;
//Ctor
Segmenter::Segmenter() : length(0), seg_number(0), seg_count(0),
retries(0)
{
//cout << "Konstruktor Segmenter" << std::endl;
send_frame.data = new uint8[DATA_LEN];//
<-------------------------------allocation works
rcvd_frame.data = new uint8[DATA_LEN];//
<--------------------------------allocation works
//send_frame.data = (uint8*)malloc(sizeof(uint8)*DATA_LEN);
//rcvd_frame.data = (uint8*)malloc(sizeof(uint8)*DATA_LEN);
p_crc = new Crc16_MC;//
<----------------------------------------------------allocation works
assert(p_crc);
}
//Dtor
Segmenter::~Segmenter()
{
cout << "Destruktor Segmenter" << std::endl;
//free(send_frame.data);
//free(rcvd_frame.data);
delete [] send_frame.data; //<-------------------------------ERROR
delete [] rcvd_frame.data; //<-------------------------------ERROR
delete p_crc; //<-------------------------------------------------
works fine
}
when I compile my c++ program, MS Visual C++ (2003) shows this error:
Damage: after Normal Block (#139) at 0xXXXXXXXX
In Debug Mode I found out that it is the deallocation with "delete" in
the destructor.
When hiding the delete, there is no error, but I want to set my data
free in the destructor before the object dies. It has something to do
with the array that is allocated, cause a deletion of the ponter
"p_crc" works perfectly. Here the code: for explanation:
//send_frame is a struct with an pointer to uint8 as one element
//typedef signed char uint8;
//uint8* data;
//Ctor
Segmenter::Segmenter() : length(0), seg_number(0), seg_count(0),
retries(0)
{
//cout << "Konstruktor Segmenter" << std::endl;
send_frame.data = new uint8[DATA_LEN];//
<-------------------------------allocation works
rcvd_frame.data = new uint8[DATA_LEN];//
<--------------------------------allocation works
//send_frame.data = (uint8*)malloc(sizeof(uint8)*DATA_LEN);
//rcvd_frame.data = (uint8*)malloc(sizeof(uint8)*DATA_LEN);
p_crc = new Crc16_MC;//
<----------------------------------------------------allocation works
assert(p_crc);
}
//Dtor
Segmenter::~Segmenter()
{
cout << "Destruktor Segmenter" << std::endl;
//free(send_frame.data);
//free(rcvd_frame.data);
delete [] send_frame.data; //<-------------------------------ERROR
delete [] rcvd_frame.data; //<-------------------------------ERROR
delete p_crc; //<-------------------------------------------------
works fine
}