mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Avoid memory leaks
Properly discard segments from the segment heap. PiperOrigin-RevId: 298704074
This commit is contained in:
committed by
gVisor bot
parent
277a0d5a1f
commit
371abe00f0
@@ -195,6 +195,10 @@ func (r *receiver) consumeSegment(s *segment, segSeq seqnum.Value, segLen seqnum
|
||||
|
||||
for i := first; i < len(r.pendingRcvdSegments); i++ {
|
||||
r.pendingRcvdSegments[i].decRef()
|
||||
// Note that slice truncation does not allow garbage collection of
|
||||
// truncated items, thus truncated items must be set to nil to avoid
|
||||
// memory leaks.
|
||||
r.pendingRcvdSegments[i] = nil
|
||||
}
|
||||
r.pendingRcvdSegments = r.pendingRcvdSegments[:first]
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ func (h *segmentHeap) Pop() interface{} {
|
||||
old := *h
|
||||
n := len(old)
|
||||
x := old[n-1]
|
||||
old[n-1] = nil
|
||||
*h = old[:n-1]
|
||||
return x
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user