Click here to Skip to main content
15,917,177 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I executed the following code :

class spchar

    char * st_string;
    long long int length;

public :


        delete []st_string;

I used this class in the main function in the following way :

spchar h = "Hello";

Upon running this code Visual C++ gives me the following error :

(The program returns the error when the h goes out of scope that is when delete operator is called in the destructor.)

Debug Error!

[Address of the application in disk]

HEAP CORRUPTION DETECTED : after Normal block(#137) at
CRT detected that the application wrote to memory after end of heap buffer.

How to troubleshoot this issue ? Further do i need to explicitly delete this pointer by issuing this command delete []st_string , wont the destructor destroy it ?
Updated 15-Jun-13 6:42am
André Kraak 15-Jun-13 12:22pm    
It might help if you added the code where the st_string variable is initialized and it memory allocated.

First off I would say you need to add a condition so that the memory is only deleted when it has actually been allocated.
compuknow 15-Jun-13 12:43pm    
I have updated the question.
Sergey Alexandrovich Kryukov 15-Jun-13 22:42pm    
Perhaps you never allocated st_string using "new" operator...
compuknow 16-Jun-13 0:42am    
I did it (used new operator , same error occurred.).I tried with structures instead of classes but did not work. Should i update the code.
Sergey Alexandrovich Kryukov 16-Jun-13 1:40am    
Are you sure, tried under the debugger? Yes, the code should be adequate enough to reproduce the problem. If one runs it as is, without what's hidden under ellipsis, it won't work anyway.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900