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.
pull/26308/head
Håvard Anda Estensen 2 years ago committed by GitHub
parent 10347c6b54
commit 06632da2bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      core/txpool/list.go
  2. 1
      core/types/transaction.go
  3. 1
      p2p/util.go

@ -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
}

@ -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
}

@ -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
}

Loading…
Cancel
Save