Skip to content

Commit

Permalink
all: assign zero after resize in implementations of heap.Interface (e…
Browse files Browse the repository at this point in the history
…thereum#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.
  • Loading branch information
estensen authored Dec 5, 2022
1 parent 10347c6 commit 06632da
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/txpool/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (h *nonceHeap) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
old[n-1] = 0
*h = old[0 : n-1]
return x
}
Expand Down
1 change: 1 addition & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ func (s *TxByPriceAndTime) Pop() interface{} {
old := *s
n := len(old)
x := old[n-1]
old[n-1] = nil
*s = old[0 : n-1]
return x
}
Expand Down
1 change: 1 addition & 0 deletions p2p/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (h *expHeap) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
old[n-1] = expItem{}
*h = old[0 : n-1]
return x
}

0 comments on commit 06632da

Please sign in to comment.