Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > dyn.alloc error

Reply
Thread Tools

dyn.alloc error

 
 
JDHawk
Guest
Posts: n/a
 
      11-14-2007
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(uint*DATA_LEN);
//rcvd_frame.data = (uint8*)malloc(sizeof(uint*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
}

 
Reply With Quote
 
 
 
 
Stefan Naewe
Guest
Posts: n/a
 
      11-14-2007
On 11/14/2007 2:24 PM, JDHawk wrote:
> 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(uint*DATA_LEN);
> //rcvd_frame.data = (uint8*)malloc(sizeof(uint*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.
--
Stefan Naewe stefan dot naewe at atlas-elektronik dot com
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
 
Reply With Quote
 
 
 
 
Jonathan Lane
Guest
Posts: n/a
 
      11-14-2007
On Nov 14, 1:24 pm, JDHawk <(E-Mail Removed)> wrote:
> 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(uint*DATA_LEN);
> //rcvd_frame.data = (uint8*)malloc(sizeof(uint*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?

 
Reply With Quote
 
tragomaskhalos
Guest
Posts: n/a
 
      11-14-2007
On Nov 14, 1:24 pm, JDHawk <(E-Mail Removed)> wrote:
> 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(uint*DATA_LEN);
> //rcvd_frame.data = (uint8*)malloc(sizeof(uint*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.



 
Reply With Quote
 
JDHawk
Guest
Posts: n/a
 
      11-14-2007
On 14 Nov., 14:42, Stefan Naewe <(E-Mail Removed)> wrote:
> On 11/14/2007 2:24 PM, JDHawk wrote:
>
>
>
> > 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(uint*DATA_LEN);
> > //rcvd_frame.data = (uint8*)malloc(sizeof(uint*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.
> --
> Stefan Naewe stefan dot naewe at atlas-elektronik dot com
> Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
> Plain text mails only, please http://www.expita.com/nomime.html


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

Thank You very much

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xffc Thread 0x228 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-30-2006 03:16 PM
Error connecting to SQLExpress 2005 locally (error: 26 - Error Locating Server/Instance Specified) hfk0 ASP .Net 2 03-27-2006 08:43 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 1 03-24-2006 04:20 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-24-2006 02:22 PM
Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error JavaQueries Java 1 03-01-2005 06:30 PM



Advertisments