From ef71887d7af119514c1d91f03b8391d47645d0ef Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 14 Jan 2025 10:56:17 +0800 Subject: [PATCH] accounts, cmd/geth, core: close opened files (#29598) * fix: open file used up but not closed * feat: more same case * feat: accept conversation --- accounts/keystore/keystore.go | 7 +++---- accounts/scwallet/hub.go | 1 + core/mkalloc.go | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/accounts/keystore/keystore.go b/accounts/keystore/keystore.go index 32580d01c1..983793e0b7 100644 --- a/accounts/keystore/keystore.go +++ b/accounts/keystore/keystore.go @@ -323,11 +323,10 @@ func (ks *KeyStore) Unlock(a accounts.Account, passphrase string) error { // Lock removes the private key with the given address from memory. func (ks *KeyStore) Lock(addr common.Address) error { ks.mu.Lock() - if unl, found := ks.unlocked[addr]; found { - ks.mu.Unlock() + unl, found := ks.unlocked[addr] + ks.mu.Unlock() + if found { ks.expire(addr, unl, time.Duration(0)*time.Nanosecond) - } else { - ks.mu.Unlock() } return nil } diff --git a/accounts/scwallet/hub.go b/accounts/scwallet/hub.go index 50b5433765..410e8f0023 100644 --- a/accounts/scwallet/hub.go +++ b/accounts/scwallet/hub.go @@ -95,6 +95,7 @@ func (hub *Hub) readPairings() error { } return err } + defer pairingFile.Close() pairingData, err := io.ReadAll(pairingFile) if err != nil { diff --git a/core/mkalloc.go b/core/mkalloc.go index 6c8a5d0ee5..0eb2e86e2d 100644 --- a/core/mkalloc.go +++ b/core/mkalloc.go @@ -78,6 +78,7 @@ func main() { if err != nil { panic(err) } + defer file.Close() if err := json.NewDecoder(file).Decode(g); err != nil { panic(err) }