From 1d527523b03a248152fe3bc2e9309fab041a0924 Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Sun, 21 Apr 2024 09:34:11 +0800 Subject: [PATCH 1/3] fix: open file used up but not closed --- accounts/keystore/keystore.go | 4 +--- accounts/scwallet/hub.go | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/accounts/keystore/keystore.go b/accounts/keystore/keystore.go index 5c978cf0b4227..b9184a23344f0 100644 --- a/accounts/keystore/keystore.go +++ b/accounts/keystore/keystore.go @@ -312,11 +312,9 @@ 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() + defer ks.mu.Unlock() if unl, found := ks.unlocked[addr]; found { - ks.mu.Unlock() 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 5f1f369ca2a02..1b1899dc8e8e1 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 { From 7cb6ebf14d59eedf48fa8a884fc0b4f69e7a9db3 Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Sun, 21 Apr 2024 09:53:00 +0800 Subject: [PATCH 2/3] feat: more same case --- cmd/geth/logging_test.go | 2 ++ cmd/utils/history_test.go | 1 + core/mkalloc.go | 1 + 3 files changed, 4 insertions(+) diff --git a/cmd/geth/logging_test.go b/cmd/geth/logging_test.go index b5ce03f4b8db1..f426b138bb67f 100644 --- a/cmd/geth/logging_test.go +++ b/cmd/geth/logging_test.go @@ -73,6 +73,7 @@ func testConsoleLogging(t *testing.T, format string, tStart, tEnd int) { if err != nil { t.Fatal(err) } + defer readFile.Close() wantLines := split(readFile) haveLines := split(bytes.NewBuffer(haveB)) for i, want := range wantLines { @@ -109,6 +110,7 @@ func TestJsonLogging(t *testing.T) { if err != nil { t.Fatal(err) } + defer readFile.Close() wantLines := split(readFile) haveLines := split(bytes.NewBuffer(haveB)) for i, wantLine := range wantLines { diff --git a/cmd/utils/history_test.go b/cmd/utils/history_test.go index b6703c59ed323..520a0d84cdfb5 100644 --- a/cmd/utils/history_test.go +++ b/cmd/utils/history_test.go @@ -113,6 +113,7 @@ func TestHistoryImportAndExport(t *testing.T) { if err != nil { t.Fatalf("error opening era file: %v", err) } + defer f.Close() var ( h = sha256.New() buf = bytes.NewBuffer(nil) diff --git a/core/mkalloc.go b/core/mkalloc.go index 201c2fe7de8d5..cc4955f0383c5 100644 --- a/core/mkalloc.go +++ b/core/mkalloc.go @@ -101,6 +101,7 @@ func main() { if err != nil { panic(err) } + defer file.Close() if err := json.NewDecoder(file).Decode(g); err != nil { panic(err) } From d96fe8996386c87e107e8d0fa050d2c8d7716a67 Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Tue, 23 Apr 2024 16:44:31 +0800 Subject: [PATCH 3/3] feat: accept conversation --- accounts/keystore/keystore.go | 5 +++-- cmd/utils/history_test.go | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/accounts/keystore/keystore.go b/accounts/keystore/keystore.go index b9184a23344f0..df3dda60b6566 100644 --- a/accounts/keystore/keystore.go +++ b/accounts/keystore/keystore.go @@ -312,8 +312,9 @@ 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() - defer ks.mu.Unlock() - if unl, found := ks.unlocked[addr]; found { + unl, found := ks.unlocked[addr] + ks.mu.Unlock() + if found { ks.expire(addr, unl, time.Duration(0)*time.Nanosecond) } return nil diff --git a/cmd/utils/history_test.go b/cmd/utils/history_test.go index 520a0d84cdfb5..b6703c59ed323 100644 --- a/cmd/utils/history_test.go +++ b/cmd/utils/history_test.go @@ -113,7 +113,6 @@ func TestHistoryImportAndExport(t *testing.T) { if err != nil { t.Fatalf("error opening era file: %v", err) } - defer f.Close() var ( h = sha256.New() buf = bytes.NewBuffer(nil)