Skip to content

Fix SafeHandle usage in System.IO.Compression #89445

Closed

Description

@CarnaViire

Discovered while fixing #86960. System.IO.Compression doesn't seem to utilize SafeHandle properly to have ref counts working during interop. See Stephen's comment below

I took a peek. I'm a little disheartened, not by your change, but by how SafeHandle is being used today in System.IO.Compression. It's not really being used how it's intended to be used. It's not storing a pointer to the data that's actually being used by the native code, so the SafeHandle isn't itself being passed through the LibraryImports, which means it's not being ref counted via DangerousAdd/Release the way it's meant to be as part of P/Invokes. As such, using DangerousAdd/Release here isn't necessarily achieving the goal.

We might want to revert "temporarily" to your previous workaround, and then separately overhaul how SafeHandle is used by all of this code.

Originally posted by @stephentoub in #87966 (comment)

After this issue is addressed, WebSockets should be updated to leverage DangerousAdd/Release

Activity

  1. ghost added
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Jul 25, 2023
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Jul 25, 2023
  3. added and removed
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Jul 25, 2023
  4. added this to the 9.0.0 milestone on Jul 26, 2023
  5. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on Jul 26, 2023
  6. modified the milestones: 9.0.0, 10.0.0 on Jul 21, 2024
  7. modified the milestones: 10.0.0, Future on Jul 26, 2025
  8. added
    in-prThere is an active PR which will close this issue when it is merged
    on Oct 16, 2025
  9. added a commit that references this issue on Nov 28, 2025
    c3d9ccd
  10. locked and limited conversation to collaborators on Dec 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.IO.Compressionin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions