Reputation: 93
When I built my visual C++project in debug mode, just with two lines of code
TEnviron * fk = new TEnviron();
delete fk;
it throws an assertion failure error _BLOCK_TYPE_IS_VALID from _CrtIsValidHeapPointer. The comment for it says
Verify pointer is not only a valid pointer but also that it is from the 'local' heap.
The TEnviron is from a different dll than my main program so it is failing. I'm in a desperate need to identify a "real" memory corruption in my software so I came to use debug build with the hope it can catch the corruption, but it is just making bogus noise, and would not let me continue beyond that statement. Can't a man write a delete statement? Please help before I get fired.
Upvotes: 1
Views: 194
Reputation: 5980
If we talk about MSVC, I personally create and delete objects of classes imported from a DLL only in that DLL. So they always exist in the DLL's heap, not main heap. I do it using a pair of static functions create/destroy. This way I can safely create and delete objects from anywhere. Maybe this is not the best solution for you, but it solves your problem.
Upvotes: 1