Reliable clean-up of SafeHandles in Deflater/Inflater #114826
+74
−59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This reimplements #71991 in
Deflater
andInflater
. The PR was previously reverted in #85001 as a result of issue #84994.As noted in the reverting PR,
Deflater
simply needed to dispose of the returned SafeHandle and supress its own finalizer ifCreateZLibStreamForDeflate
threw an exception. We now do this.We couldn't do this for
Inflater
at the time - it had to support concatenated GZip data, and as part of that support it would recreate itsZLibStreamHandle
. As a result of #113587, this recreation no longer happens and we can treatInflater
as we would treatDeflater
. I've refactoredInflater.InflateInit
out of existence and made_zlibStream
readonly to reflect this.This also incorporates a change to both class'
DeallocateBufferHandle
methods (when called byDispose
) to prevent them dereferencing aZLibStreamHandle
after it's been disposed of. This is roughly how #84994 was originally discovered.