-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Question: do I need to dispose the X509Certificate2 elements in an X509Chain myself? #112987
Comments
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones |
Correct. You can see that in places we use Lines 736 to 744 in bfc8814
Calling Some possible follow up questions, answered. Is it a memory leak if I don't dispose of the chain elements? No, they will be cleaned up by a finalizer for the underlying certificate PAL. Why not dispose of the chain elements when This is how .NET Framework does it, so it has been this way for a long time. Changing it now would be a breaking change (because if we did dispose of the chain elements, then they would become unusable after the chain is disposed, which some people may, and likely, have a dependency on). |
Thank you for your detailed answer! As a small suggestion: this should probably be documented in the X509Chain class docs. |
(sorry, fat fingered something on my phone)
In particular, with a certificate chain it's quite likely that multiple chains will be built with the same root certificate, and if disposing of the chain disposed of all certificates it would force reloading of the root (and intermediate) certificates. |
That's probably reasonable. Where would you generally expect to see this documented? There are a couple of places that are reasonable
|
@vcsjones I looked at all those places, so it wouldn't have mattered much. Foremost I guess on the X509Chain class itself. |
I've experienced that the following code works just fine:
It looks like the X509Certificate2 objects inside a chain are not disposed with the chain. Is that so? Do I need to dispose them myself when I dispose the chain to do proper cleanup?
Best regards,
D.R.
The text was updated successfully, but these errors were encountered: