Skip to content

Why is adding/removing a reference to a SafeHandle "dangerous"? #101980

Answered by stephentoub
colejohnson66 asked this question in Q&A
Discussion options

You must be logged in to vote

Because once you call add, the handle will be leaked unless a corresponding release call is made, and finalization won't help. And because anyone who has that reference can call release even if they didn't call add, which means code that's using the handle correctly can still experience use-after-free bugs if code elsewhere misuses that instance. The naming is just there to say "be really careful here, there be dragons".

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@colejohnson66
Comment options

@stephentoub
Comment options

@colejohnson66
Comment options

@stephentoub
Comment options

@colejohnson66
Comment options

Answer selected by colejohnson66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants