-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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: unmanaged memory leak on parsing ill-formed certificates #93647
Conversation
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones Issue DetailsThere is a memory leak - unmanaged! - because ParsePkcs12 is called from ctors and in case of an exception is thrown allocated resources won't be released inside the call nor by GC.
|
@dotnet-policy-service agree |
Wouldn't the proper fix here be to implement a finalizer on the base class in |
I've tried to do it the simplest way. The problem is in base class, true, but it also doesn't fully implement Dispose pattern so there will be more changes to separate managed/unmanaged cleanup - and without that it looks unsafe in finalizer. |
So shouldn't the fix be to make it so it does? |
In discussion about a different approach in a different medium
I'll rework it to proper Dispose pattern |
I think the better approach is to just remove the constructor argument and move it to a load function, that way Dispose will automatically fire and things just work. using (Pkcs12Reader reader = new WhateverKind())
{
reader.Load(data);
...
} |
That could be done although it'll break class contract. But I think proper Dispose - with finalizer - should be implemented anyway since there is an unmanaged resource and the class is not sealed. |
This was addressed in #98331 by following the strategy outlined in #93647 (comment) |
There is a memory leak - unmanaged! - because ParsePkcs12 is called from ctors and in case of an exception is thrown allocated resources won't be released inside the call nor by GC.