Commit d6a73329 authored by Felix Lange's avatar Felix Lange

accounts: fix uses of sync.RWMutex

RWMutexes must be write-locked when writing in order
to actually protect the writes.
parent afc530ea
...@@ -111,9 +111,9 @@ func (am *AccountManager) SignLocked(a Account, keyAuth string, toSign []byte) ( ...@@ -111,9 +111,9 @@ func (am *AccountManager) SignLocked(a Account, keyAuth string, toSign []byte) (
if err != nil { if err != nil {
return nil, err return nil, err
} }
am.mutex.RLock() am.mutex.Lock()
am.unlockedKeys[string(a.Address)] = *key am.unlockedKeys[string(a.Address)] = *key
am.mutex.RUnlock() am.mutex.Unlock()
go unlockLater(am, a.Address) go unlockLater(am, a.Address)
signature, err = crypto.Sign(toSign, key.PrivateKey) signature, err = crypto.Sign(toSign, key.PrivateKey)
return signature, err return signature, err
...@@ -147,8 +147,10 @@ func unlockLater(am *AccountManager, addr []byte) { ...@@ -147,8 +147,10 @@ func unlockLater(am *AccountManager, addr []byte) {
select { select {
case <-time.After(am.unlockTime): case <-time.After(am.unlockTime):
} }
am.mutex.RLock() am.mutex.Lock()
// TODO: how do we know the key is actually gone from memory? // TODO: how do we know the key is actually gone from memory?
delete(am.unlockedKeys, string(addr)) delete(am.unlockedKeys, string(addr))
am.mutex.RUnlock() am.mutex.Unlock()
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment