diff options
| author | Dan Engelbrecht <[email protected]> | 2025-08-21 09:54:34 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-08-21 09:54:34 +0200 |
| commit | 05b69c12a71d2725b4ccba3970b0a7e41040786c (patch) | |
| tree | f7a1f7200774d1f057ef52552ab54b1a064ca18b /src/zencore | |
| parent | per namespace/project cas prep refactor (#470) (diff) | |
| download | zen-05b69c12a71d2725b4ccba3970b0a7e41040786c.tar.xz zen-05b69c12a71d2725b4ccba3970b0a7e41040786c.zip | |
avoid new in static IoBuffer (#472)
Diffstat (limited to 'src/zencore')
| -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)) { |