Skip to content

Commit f8820f1

Browse files
authored
accounts, cmd/geth, core: close opened files (#29598)
* fix: open file used up but not closed * feat: more same case * feat: accept conversation
1 parent 45baf21 commit f8820f1

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

accounts/keystore/keystore.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,10 @@ func (ks *KeyStore) Unlock(a accounts.Account, passphrase string) error {
312312
// Lock removes the private key with the given address from memory.
313313
func (ks *KeyStore) Lock(addr common.Address) error {
314314
ks.mu.Lock()
315-
if unl, found := ks.unlocked[addr]; found {
316-
ks.mu.Unlock()
315+
unl, found := ks.unlocked[addr]
316+
ks.mu.Unlock()
317+
if found {
317318
ks.expire(addr, unl, time.Duration(0)*time.Nanosecond)
318-
} else {
319-
ks.mu.Unlock()
320319
}
321320
return nil
322321
}

accounts/scwallet/hub.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func (hub *Hub) readPairings() error {
9595
}
9696
return err
9797
}
98+
defer pairingFile.Close()
9899

99100
pairingData, err := io.ReadAll(pairingFile)
100101
if err != nil {

cmd/geth/logging_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func testConsoleLogging(t *testing.T, format string, tStart, tEnd int) {
7373
if err != nil {
7474
t.Fatal(err)
7575
}
76+
defer readFile.Close()
7677
wantLines := split(readFile)
7778
haveLines := split(bytes.NewBuffer(haveB))
7879
for i, want := range wantLines {
@@ -109,6 +110,7 @@ func TestJsonLogging(t *testing.T) {
109110
if err != nil {
110111
t.Fatal(err)
111112
}
113+
defer readFile.Close()
112114
wantLines := split(readFile)
113115
haveLines := split(bytes.NewBuffer(haveB))
114116
for i, wantLine := range wantLines {

core/mkalloc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func main() {
101101
if err != nil {
102102
panic(err)
103103
}
104+
defer file.Close()
104105
if err := json.NewDecoder(file).Decode(g); err != nil {
105106
panic(err)
106107
}

0 commit comments

Comments
 (0)