Page 1 of 1

core::string destructor is crashing

Posted: Tue Apr 04, 2017 8:42 am
by DanielBocksteger
Hi there,

we've a class, holding some core::stringw properties. When the system (iOS) calls the destructor, it sometimes crashes because the following code tries to free memory space, that hasn't been allocated yet.

1. Class destructor calls iiString.cpp ~string() destructor

Code: Select all

//! Destructor
~string()
{
    allocator.deallocate(array); // delete [] array;
}
2. ... calls irrAllocator.h deallocate(T * ptr)

Code: Select all

//! Deallocate memory for an array of objects
void deallocate(T* ptr)
{
    internal_delete(ptr);
}
3. ... calls irrAllocator.h internal_delete(void* ptr)

Code: Select all

virtual void internal_delete(void* ptr)
{
    operator delete(ptr); // malloc: *** error for object 0x170817650: pointer being freed was not allocated
}
Can anybody tell me, how to solve this issue?

Regards,
Daniel

Re: core::string destructor is crashing

Posted: Tue Apr 04, 2017 10:19 am
by CuteAlien
Chances are pretty high that the problem is in another place. For example the string is in some other class and that other class object is invalid that point. For such bugs you have to reduce the problem until you have only a tiny program left which still contains the bug (divide&conquer!). Then you can post that tiny program (which should still compile, but not contain any line anymore which isn't removable while keeping the bug) so others can look at it. Thought usually you find the problem yourself while reducing code like that :-)