diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/zencore/iobuffer.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/zencore/iobuffer.cpp b/src/zencore/iobuffer.cpp index 8e9a37a27..be9b39e7a 100644 --- a/src/zencore/iobuffer.cpp +++ b/src/zencore/iobuffer.cpp @@ -429,7 +429,25 @@ IoBufferExtendedCore::SetDeleteOnClose(bool DeleteOnClose) ////////////////////////////////////////////////////////////////////////// -RefPtr<IoBufferCore> IoBuffer::NullBufferCore(new IoBufferCore); +static IoBufferCore* +GetNullBufferCore() +{ + // This is safe from a threading standpoint since the first call is non-threaded (during static init) and for the following + // calls Core is never nullptr + // We do this workaround since we don't want to call new (IoBufferCore) at static initializers + // Calling new during static initialize causes problem with memtracing since the flags are not set up correctly yet + + static IoBufferCore NullBufferCore; + static IoBufferCore* Core = nullptr; + if (Core == nullptr) + { + Core = &NullBufferCore; + Core->AddRef(); // Make sure we never deallocate it as it is a static instance + } + return Core; +} + +RefPtr<IoBufferCore> IoBuffer::NullBufferCore(GetNullBufferCore()); IoBuffer::IoBuffer(size_t InSize) : m_Core(new IoBufferCore(InSize)) { |