From 06632da2bb367664b5e1417c55c0d3a2a2bf5166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Anda=20Estensen?= Date: Mon, 5 Dec 2022 13:49:54 +0100 Subject: [PATCH] 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. --- core/txpool/list.go | 1 + core/types/transaction.go | 1 + p2p/util.go | 1 + 3 files changed, 3 insertions(+) diff --git a/core/txpool/list.go b/core/txpool/list.go index eb0c753f21..062cbbf63e 100644 --- a/core/txpool/list.go +++ b/core/txpool/list.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 } diff --git a/core/types/transaction.go b/core/types/transaction.go index 910c68aea3..353e0e599c 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -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 } diff --git a/p2p/util.go b/p2p/util.go index 3c5f6b8508..2c8f322a66 100644 --- a/p2p/util.go +++ b/p2p/util.go @@ -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 }