Avoid leaking more popped items (#8145)

This commit is contained in:
Alex Sharov 2023-09-06 15:47:06 +07:00 committed by GitHub
parent ef84972e7c
commit d60940d7db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 5 deletions

View File

@ -112,7 +112,7 @@ func (bp *PeersByMinBlock) Pop() interface{} {
old := *bp
n := len(old)
x := old[n-1]
old[n-1] = PeerRef{}
old[n-1] = PeerRef{} // avoid memory leak
*bp = old[0 : n-1]
return x
}

View File

@ -372,7 +372,7 @@ func (s *TxByPriceAndTime) Pop() interface{} {
old := *s
n := len(old)
x := old[n-1]
old[n-1] = nil
old[n-1] = nil // avoid memory leak
*s = old[0 : n-1]
return x
}
@ -500,6 +500,7 @@ func (t *TransactionsFixedOrder) Peek() Transaction {
// Shift replaces the current best head with the next one from the same account.
func (t *TransactionsFixedOrder) Shift() {
t.Transactions[0] = nil // avoid memory leak
t.Transactions = t.Transactions[1:]
}
@ -507,6 +508,7 @@ func (t *TransactionsFixedOrder) Shift() {
// the same account. This should be used when a transaction cannot be executed
// and hence all subsequent ones should be discarded from the same account.
func (t *TransactionsFixedOrder) Pop() {
t.Transactions[0] = nil // avoid memory leak
t.Transactions = t.Transactions[1:]
}

View File

@ -197,7 +197,7 @@ func (t *transactionsByGasPrice) Pop() interface{} {
old := t.txs
n := len(old)
x := old[n-1]
old[n-1] = nil
old[n-1] = nil // avoid memory leak
t.txs = old[0 : n-1]
return x
}
@ -276,7 +276,7 @@ func (s *sortingHeap) Pop() interface{} {
old := *s
n := len(old)
x := old[n-1]
old[n-1] = nil
old[n-1] = nil // avoid memory leak
*s = old[0 : n-1]
return x
}

View File

@ -197,7 +197,7 @@ func (iq *InsertQueue) Pop() interface{} {
old := *iq
n := len(old)
x := old[n-1]
old[n-1] = nil
old[n-1] = nil // avoid memory leak
*iq = old[0 : n-1]
x.idx = -1
x.queueId = NoQueue