Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crash when deleting object

Status
Not open for further replies.

banah

Technical User
Nov 25, 2001
1
0
0
US
I have a pointer to a char in a structure that I use to make a linked list. However, the program crashes when attempting to delete the allocated memory for *char member of the structure. Any ideas?

Here is an example:

struct record
{
char *buffer;
rec *next;
};

typedef record *rec;
...
rec = new rec;
rec->buffer = new char[255];
strcpy (rec->buffer,"Hello");
delete []rec->buffer; // this is where it crashes. Why?
...

If I allocate memory to a non-structure pointer to char member and delete it, it works with no problems.

Thank you for any help with this.
 
try to ask this question in the visual c++ forum, or c++, maybe more technical experts can be found in these
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top