Hi,
The following code causes a wrong free() call:
String crack(T("crack"));
for (int i = 0; i < 0x40000000; ++i)
{
String s;
s = crack;
}
The problem is related to the reference counting of String::emptyString. Each time the “s = crack” code is executed, the number of references of String::emptyString is decremented until reaching 0, which causes the (statically allocated) empty string to be freed.
Here is a dirty hack in String::operator= (const String& other):
if (text != &emptyString && atomicDecrementAndReturn (text->refCount) == 0)
juce_free (text);
But I think that there is probably a better way to solve the problem.
Regards,
Francis.