This PR fixes a memory leak on shaXHash.Clone(). The returned instance owns a bcrypt.HASH_HANDLE allocated using bcrypt.DuplicateHash. The logic to free the context memory resides in shaXHash.finalize, which should be called automatically when the sha instance is garbage collected.
The problem is that Go doesn't know it has to call shaXHash.finalize, we have to instruct it by calling runtime.SetFinalizer(h, (*shaXHash).finalize) just after instantiating the sha. And we are not doing that.
This PR fixes a memory leak on
shaXHash.Clone()
. The returned instance owns abcrypt.HASH_HANDLE
allocated usingbcrypt.DuplicateHash
. The logic to free the context memory resides inshaXHash.finalize
, which should be called automatically when the sha instance is garbage collected.The problem is that Go doesn't know it has to call
shaXHash.finalize
, we have to instruct it by calling runtime.SetFinalizer(h, (*shaXHash).finalize) just after instantiating the sha. And we are not doing that.