-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory leaks. #625
Fix memory leaks. #625
Conversation
For some background reading... The onus of this is that on Gehn Beta, downloading a new copy of @DoobesURU Age Veelay Tsahvahn can cause the client to crash shortly after linking in with an |
54f80b6
to
b354522
Compare
0d4b2a5
to
08b3105
Compare
I recently received a complaint in IRC that boiled down to folks with large buddy lists saw |
Prior to these changes, the client would crash on MOULa in an hour or less. After these changes, it stayed up for over 10 hours with no problems. |
Sources/Plasma/CoreLib/hsRefCnt.cpp
Outdated
@@ -123,7 +123,7 @@ hsRefCnt::hsRefCnt(int initRefs) | |||
hsRefCnt::~hsRefCnt() | |||
{ | |||
#ifdef HS_DEBUGGING | |||
hsThrowIfFalse(fRefCnt == 1); | |||
hsThrowIfFalse(fRefCnt <= 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What cases do we want to support where the ref count is < 1
? I feel like we should catch too-many-unrefs as well as too few...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NetVaultNode
's starting reference count is zero. An earlier refactor changed its base class from AtomicRef
to hsRefCnt
but neglected to address the difference in starting ref count, introducing all of these leaks. I initially wanted to add a template parameter for the starting ref count to hsRefCnt
, but I wasn't able to come up with a clean solution that didn't expose implementation details to the rest of the engine
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoListNode.cpp
Outdated
Show resolved
Hide resolved
Part of the problem here is the mix of managed ( Perhaps instead of the struct hsAdoptRef_Type {};
constexpr hsAdoptRef_Type hsAdoptRef;
template <class _Ref>
class hsRef
{
public:
/* ... */
hsRef(_Ref *obj, hsAdoptRef_Type) : fObj(obj) { }
/* ... */
void Adopt(_Ref *obj)
{
if (fObj)
fObj->UnRef();
fObj = obj;
return *this;
}
/* ... */
}; Then in usage: hsRef<Whatever> myref(new Whatever, hsAdoptRef);
// or
hsRef<Whatever> myref;
myref.Adopt(new Whatever); In the long run, we'd want to eventually ensure that promotion from a "raw" |
Agreed. I'll look into this, although I may change |
When `hsRef` is constructed from a pointer, it increments the reference count. Originally, the `NetVaultNode` reference count started at zero, so this was fine. However, when the various reference counting bases were consolidated, `NetVaultNode`'s count became one. This means that any instance of `hsRef<NetVaultNode> ref = new NetVaultNode;` would have a reference count of two, causing the object to be leaked.
It compiles! |
|
💥 |
This changeset fixes a major source of memory leaks in the vault client API. Any time
hsRef<NetVaultNode> foo = new NetVaultNode;
was called resulted in a leak due to a change in behavior when the old AtomicRef was merged with hsRefCnt.