Avoiding leaking the popped item (#6193)

Set the deleted item to its zero val so it can be garbage collected.
This commit is contained in:
Håvard Anda Estensen 2022-12-04 05:17:02 +01:00 committed by GitHub
parent 099fb7c627
commit 31ec791d5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 0 deletions

View File

@ -105,6 +105,7 @@ func (bp *PeersByMinBlock) Pop() interface{} {
old := *bp
n := len(old)
x := old[n-1]
old[n-1] = PeerRef{}
*bp = old[0 : n-1]
return x
}

View File

@ -319,6 +319,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
}

View File

@ -211,6 +211,7 @@ func (t *transactionsByGasPrice) Pop() interface{} {
old := t.txs
n := len(old)
x := old[n-1]
old[n-1] = nil
t.txs = old[0 : n-1]
return x
}
@ -289,6 +290,7 @@ func (s *sortingHeap) Pop() interface{} {
old := *s
n := len(old)
x := old[n-1]
old[n-1] = nil
*s = old[0 : n-1]
return x
}

View File

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

View File

@ -87,6 +87,7 @@ func (lq *LinkQueue) Pop() interface{} {
old := *lq
n := len(old)
x := old[n-1]
old[n-1] = nil
x.idx = -1
x.queueId = NoQueue
*lq = old[0 : n-1]
@ -152,6 +153,7 @@ func (aq *AnchorQueue) Pop() interface{} {
old := *aq
n := len(old)
x := old[n-1]
old[n-1] = nil
*aq = old[0 : n-1]
x.idx = -1
return x
@ -243,6 +245,7 @@ func (iq *InsertQueue) Pop() interface{} {
old := *iq
n := len(old)
x := old[n-1]
old[n-1] = nil
*iq = old[0 : n-1]
x.idx = -1
x.queueId = NoQueue