Skip to content

Commit 06632da

Browse files
authored
all: assign zero after resize in implementations of heap.Interface (#26296)
This changes the Pop method to assign the zero value before reducing slice size. Doing so ensures the backing array does not reference removed item values.
1 parent 10347c6 commit 06632da

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

core/txpool/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (h *nonceHeap) Pop() interface{} {
4545
old := *h
4646
n := len(old)
4747
x := old[n-1]
48+
old[n-1] = 0
4849
*h = old[0 : n-1]
4950
return x
5051
}

core/types/transaction.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ func (s *TxByPriceAndTime) Pop() interface{} {
508508
old := *s
509509
n := len(old)
510510
x := old[n-1]
511+
old[n-1] = nil
511512
*s = old[0 : n-1]
512513
return x
513514
}

p2p/util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func (h *expHeap) Pop() interface{} {
7070
old := *h
7171
n := len(old)
7272
x := old[n-1]
73+
old[n-1] = expItem{}
7374
*h = old[0 : n-1]
7475
return x
7576
}

0 commit comments

Comments
 (0)