Skip to content

Commit

Permalink
Avoiding leaking the popped item (erigontech#6193)
Browse files Browse the repository at this point in the history
Set the deleted item to its zero val so it can be garbage collected.
  • Loading branch information
estensen authored Dec 4, 2022
1 parent 099fb7c commit 31ec791
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/sentry/sentry/sentry_grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
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
}
3 changes: 3 additions & 0 deletions turbo/stages/headerdownload/header_data_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 31ec791

Please sign in to comment.