dyn.alloc error

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
}
 
S

Stefan Naewe

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
}

Did you implement the Copy C'tor _correctly_ ?
(Why not use a std::vector ?) ?

S.
 
J

Jonathan Lane

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

}
What happens in the meantime? Usually memory damage like that
indicates that something's already gone wrong. Usually that's a double
delete on the pointer or a memory overflow.

if I write:
int main(int argc, char** argv)
{
Segmenter s;
}

does that produce the error?
 
T

tragomaskhalos

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

It's a common mistake to assume that because an error occurs at
a particular deallocation, the fault must lie there or in the
corresponding allocation. In fact what's almost certainly happened
is some other part of your program (which you haven't posted)
is corrupting the heap, whereupon basically all bets are off.
I'd start by checking that you're not overrunning the bounds of
either send_frame.data or rcvd_frame.data (the perils of using
raw arrays, std::vector would be better here for precisely this
reason), and then broaden the search.
 
J

JDHawk

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
}

Did you implement the Copy C'tor _correctly_ ?
(Why not use a std::vector ?) ?

S.

I got the error:
I added one '\0' at the end of data and so exceeded the dyn. range.

Thank You very much
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top