#75 Static Initialization Order problem

open
nobody
None
5
2008-07-07
2008-07-07
No

Hi,

I am compiling the Debug and Release Unicode version (the static library) but with CRT DLL (the default project is CRT) and I am finding a crash due to static initialization of the strings in the fustringbuilder.cpp:

---
...
const fm::string emptyString(emptyCharString);
...
---

This static var if calling the Allocate() function (in fmallocator.cpp), and that function is using a static variable:

---
AllocateFunc af = malloc;
--

But this static is not yet initialized so it is null.

I have patched the code to chech for it and it is working right for me:

--
AllocateFunc af = 0;
FreeFunc ff = 0;

void SetAllocationFunctions(AllocateFunc a, FreeFunc f)
{
af = a;
ff = f;
}

// These two are simple enough, but have the advantage of
// always allocating/releasing memory from the same heap.
void* Allocate(size_t byteCount)
{
if (af != 0)
{
return (*af)(byteCount);
}
else
{
return malloc(byteCount);
}

}

void Release(void* buffer)
{
if (ff != 0)
{
(*ff)(buffer);
}
else
{
return free(buffer);
}
}
--

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks