fix: Fixes ObjectPropertyList double return issue (#1969)
- Fixes double return issue with object property list that is causing corruption. - Adds DEBUG_ARRAYPOOL define constant which will crash on double return or invalid return scenarios. > [!IMPORTANT] > **Developer Notes** > STArrayPool rented arrays **MUST NOT** be returned **ONLY ONCE** otherwise there will be corruption from double-use. > Use `DEBUG_ARRAYPOOL` to test potential broken STArrayPool use cases. > [!NOTE] > **Why can't I enable the debug all the time?** > Other than the fact that it will crash due to bad code, the actual tracking system is highly detrimental/problematic for performance and memory consumption by creating objects that have a stack trace.
This commit is contained in:
parent
4b3b2839c6
commit
b9d63e4160
3 changed files with 69 additions and 8 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2023 - ModernUO Development Team *
|
||||
* Copyright 2019-2024 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: ObjectPropertyList.cs *
|
||||
* *
|
||||
|
|
@ -79,8 +79,9 @@ public sealed class ObjectPropertyList : IPropertyList, IDisposable
|
|||
_stringNumbersIndex = 0;
|
||||
Header = 0;
|
||||
HeaderArgs = null;
|
||||
STArrayPool<char>.Shared.Return(_arrayToReturnToPool);
|
||||
_pos = 0;
|
||||
|
||||
Dispose();
|
||||
}
|
||||
|
||||
private void Flush()
|
||||
|
|
@ -499,13 +500,19 @@ public sealed class ObjectPropertyList : IPropertyList, IDisposable
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
STArrayPool<char>.Shared.Return(_arrayToReturnToPool);
|
||||
_arrayToReturnToPool = null;
|
||||
if (_arrayToReturnToPool != null)
|
||||
{
|
||||
STArrayPool<char>.Shared.Return(_arrayToReturnToPool);
|
||||
_arrayToReturnToPool = null;
|
||||
}
|
||||
}
|
||||
|
||||
~ObjectPropertyList()
|
||||
{
|
||||
STArrayPool<char>.Shared.Return(_arrayToReturnToPool);
|
||||
_arrayToReturnToPool = null;
|
||||
if (_arrayToReturnToPool != null)
|
||||
{
|
||||
STArrayPool<char>.Shared.Return(_arrayToReturnToPool);
|
||||
_arrayToReturnToPool = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue