fix: race condition on memory clearing

This commit is contained in:
Cassandra Heart 2023-09-25 05:00:35 -05:00
parent 2525c4ce7e
commit 05acdbf56f
No known key found for this signature in database
GPG Key ID: 6352152859385958

View File

@ -422,13 +422,16 @@ func (p *PebbleClockStore) GetMasterClockFrame(
return nil, errors.Wrap(err, "get master clock frame") return nil, errors.Wrap(err, "get master clock frame")
} }
copied := make([]byte, len(value))
copy(copied[:], value[:])
defer closer.Close() defer closer.Close()
frame := &protobufs.ClockFrame{} frame := &protobufs.ClockFrame{}
frame.FrameNumber = frameNumber frame.FrameNumber = frameNumber
frame.Filter = filter frame.Filter = filter
frame.Difficulty = binary.BigEndian.Uint32(value[:4]) frame.Difficulty = binary.BigEndian.Uint32(copied[:4])
frame.Input = value[4 : len(value)-516] frame.Input = copied[4 : len(copied)-516]
frame.Output = value[len(value)-516:] frame.Output = copied[len(copied)-516:]
previousSelectorBytes := [516]byte{} previousSelectorBytes := [516]byte{}
copy(previousSelectorBytes[:], frame.Input[:516]) copy(previousSelectorBytes[:], frame.Input[:516])