Deleting Char Array Causes Windows Break-Point

Whenever I try to delete a char array (pointer) in a class's destructor, I end up getting an error message (apparently from Windows) saying this:

Windows has triggered a breakpoint in Lag Tracking Test.exe.

This may be due to a corruption of the heap, which indicates a bug in Lag Tracking Test.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while Lag Tracking Test.exe has focus.

The output window may have more diagnostic information.


Here is the code I'm using:

1
2
3
4
lag_entry::~lag_entry( ){
	delete [] label;
	delete [] subclass;
}


The object is being deleted by using delete on a pointer to the object. I do not use delete &object;. The 2 char arrays are initialized at the time of attempted deletion.

Am I deleting the char arrays incorrectly? Or is there something going wrong in some other part of my code?
Did you allocate them with new?
Last edited on
I made a function specifically for that purpose. I had a feeling that the improperly initialized chars were screwing with the other variables in the class due to buffer overflow, so I made that. Want that function as well?
Last edited on
Show how you allocate label and subclass.

Also, did this happen while debugging or running a debug version of the EXE? If yes, then note that allocation functions in the debug library have additional checking of the state. If you allocate 10 bytes and you write 11, you might not have noticed it at the moment, but the second you do delete[] the debug library checks for the integrity of the RAM allocated and notices the extra byte, notifying you of the problem. So, it could be an allocation problem, but can also be that you are not allocating enough.
At this point, 50% of my code deals with allocation... T_T

All char arrays are initialized to NULL in the class's constructor. The values are assigned by using the following function:

1
2
3
4
5
6
7
void assign( char** destination, char* value ){
	cout << "ASSIGN" << endl;
	if( *destination != NULL )
		delete [] *destination;
	*destination = new char[strlen(value)];
	strcpy( *destination, value );
}


The cout was simply to see where the function was called, since I don't know how to get to the call stack. Should I be allocating to the length of 'value' + 1, for the null character?

And by the way, I'm not running the debug version. I'm running under Release, since VC++ often gave me assertion errors.
Last edited on
memory stomp.

the array has to be strlen(value) + 1 bytes wide to accomodate the \0
Topic archived. No new replies allowed.