channeldb: copy value from boltdb's Get instead of using it directly

This can cause an intermittent panic otherwise if bbolt remaps itself
via munmap and mmap. From bbolt's documentation:

* Byte slices returned from Bolt are only valid during a transaction.
Once the transaction has been committed or rolled back then the memory
they point to can be reused by a new page or can be unmapped from
virtual memory and you'll see an unexpected fault address panic when
accessing it.
This commit is contained in:
eugene 2022-05-17 11:14:40 -04:00
parent b31640e6b0
commit 2e3246aafe
No known key found for this signature in database
GPG Key ID: 118759E83439A9B1

View File

@ -1254,11 +1254,13 @@ func (c *ChannelStateDB) GetChannelOpeningState(outPoint []byte) ([]byte, error)
return ErrChannelNotFound
}
serializedState = bucket.Get(outPoint)
if serializedState == nil {
stateBytes := bucket.Get(outPoint)
if stateBytes == nil {
return ErrChannelNotFound
}
serializedState = append(serializedState, stateBytes...)
return nil
}, func() {
serializedState = nil