Skip to content

Commit

Permalink
fix hashX.Clone
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Dec 20, 2024
1 parent 74f51cc commit 9b21315
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cng/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,13 @@ func (h *hashX) init() {
func (h *hashX) Clone() (hash.Hash, error) {
defer runtime.KeepAlive(h)
h2 := &hashX{alg: h.alg, key: bytes.Clone(h.key)}
err := bcrypt.DuplicateHash(h.ctx, &h2.ctx, nil, 0)
if err != nil {
return nil, err
if h.ctx != 0 {
err := bcrypt.DuplicateHash(h.ctx, &h2.ctx, nil, 0)
if err != nil {
return nil, err
}
runtime.SetFinalizer(h2, (*hashX).finalize)
}
runtime.SetFinalizer(h2, (*hashX).finalize)
return h2, nil
}

Expand Down

0 comments on commit 9b21315

Please sign in to comment.