473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

dyn.alloc error

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
}

Nov 14 '07 #1
4 1426
On Nov 14, 1:24 pm, JDHawk <gentleman....@gmx.dewrote:
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?

Nov 14 '07 #2
On Nov 14, 1:24 pm, JDHawk <gentleman....@gmx.dewrote:
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.

Nov 14 '07 #3
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(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.
--
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
Nov 14 '07 #4
On 14 Nov., 14:42, Stefan Naewe <nos...@please.netwrote:
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(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.
--
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

Nov 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Adam Hartshorne | last post by:
Hi All, I have the strangest problem, and at an end to try and explain it/know what to do. I have a program written in c++ using visual studio 7.1. It was all working no problems, then after...
7
by: sNOiSPAMt | last post by:
7.20.3#1 If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value,...
10
by: Ryan Wang | last post by:
Hi, here is the function: int sum(int a,int b) { int c; c = a + b; return c; }
3
by: -DG- | last post by:
I'm still trying to figure out some of the nuances of access to legacy Win32 DLLs. I need to alloc buffers to be used by the Win32 DLLs. I know that pinning a managed pointer can lead to...
2
by: cnliou | last post by:
Linux 2.4.23 on AMD 450MHz. pgsql 7.4.1 configure --enable-multibyte=UNICODE locale is zh_TW.Big5 IIRC, when I did "initdb -E UNICODE" or "createdb db1", I saw the following message from...
1
by: John Hagstrand | last post by:
Hello, I'm getting the following error when I try to update or insert into a table. This just started happening today. The table has been working fine up to now. The table has 27,000 rows and...
5
by: Janning Vygen | last post by:
Hi, tonight my database got corruppted. before it worked fine. since two days i do the following tasks every night psql -c 'CLUSTER;' $DBNAME psql -c 'VACUUM FULL ANALYZE;' $DBNAME ...
17
by: Joe Smith | last post by:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #define BUF_MAX 80 int main (void) { char buf;
1
by: =?Utf-8?B?SkE=?= | last post by:
I use a method for threading that instantiates an object that is a wrapper to a DLL (written in C). The wrapper class is passed a byte array, and then does GCHandle handle =...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.