Skip to content

Update from SetFinalizer to AddCleanup#158

Draft
michelle-clayton-work wants to merge 5 commits intomainfrom
dev/mclayton/update-addCleanup
Draft

Update from SetFinalizer to AddCleanup#158
michelle-clayton-work wants to merge 5 commits intomainfrom
dev/mclayton/update-addCleanup

Conversation

@michelle-clayton-work
Copy link

This pull request refactors resource cleanup throughout the xcrypto package, replacing the use of runtime.SetFinalizer with the more robust runtime.AddCleanup mechanism. It introduces dedicated cleanup functions for each type of cryptographic resource, improving code clarity and reliability of resource management. The changes affect cipher, hash, HMAC, RC4, and RSA key types.

Resource cleanup modernization:

  • Replaced all uses of runtime.SetFinalizer with runtime.AddCleanup for cryptographic objects in cipher.go, hash.go, hmac.go, rc4.go, and rsa.go, ensuring more explicit and reliable cleanup of native resources. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Introduction of cleanup helper functions:

  • Added new cleanup helper functions (cryptorCleanup, hashCleanup, hmacCleanup, secKeyCleanup) and supporting info structs to encapsulate resource release logic for each cryptographic type, improving maintainability and reducing code duplication. [1] [2] [3] [4]

Removal of legacy finalizer methods:

  • Removed all type-specific finalize methods and inline finalizer functions, consolidating cleanup logic into the new helper functions. [1] [2] [3] [4] [5] [6] [7]

These changes make resource management more explicit and robust, reducing the risk of memory leaks and simplifying future maintenance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments