Hold wallet map lock until wallet has been added (or an error happens)

This commit is contained in:
Josh Rickmar 2013-10-08 19:36:44 -04:00
parent 2e42efef53
commit 94d4bd28ae

View file

@ -664,14 +664,14 @@ func CreateEncryptedWallet(reply chan []byte, msg *btcjson.Message) {
} }
// Does this wallet already exist? // Does this wallet already exist?
wallets.RLock() wallets.Lock()
if w := wallets.m[wname]; w != nil { if w := wallets.m[wname]; w != nil {
e := WalletInvalidAccountName e := WalletInvalidAccountName
e.Message = "Wallet already exists." e.Message = "Wallet already exists."
ReplyError(reply, msg.Id, &e) ReplyError(reply, msg.Id, &e)
return return
} }
wallets.RUnlock() defer wallets.Unlock()
var net btcwire.BitcoinNet var net btcwire.BitcoinNet
if cfg.MainNet { if cfg.MainNet {
@ -700,9 +700,7 @@ func CreateEncryptedWallet(reply chan []byte, msg *btcjson.Message) {
// connected to btcd. // connected to btcd.
bw.Track() bw.Track()
wallets.Lock()
wallets.m[wname] = bw wallets.m[wname] = bw
wallets.Unlock()
ReplySuccess(reply, msg.Id, nil) ReplySuccess(reply, msg.Id, nil)
} }