summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/inotify.go
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2020-03-06 12:30:37 -0800
committergVisor bot <gvisor-bot@google.com>2020-03-06 12:31:43 -0800
commit6fa5cee82c0f515b001dee5f3840e1f875b2f477 (patch)
treeadec65de9c23995348e898b3e52077edabf3b0c9 /pkg/sentry/fs/inotify.go
parent18d41cf15368c4d091ffdf84da655994eb1a1099 (diff)
Prevent memory leaks in ilist
When list elements are removed from a list but not discarded, it becomes important to invalidate the references they hold to their former neighbors to prevent memory leaks. PiperOrigin-RevId: 299412421
Diffstat (limited to 'pkg/sentry/fs/inotify.go')
-rw-r--r--pkg/sentry/fs/inotify.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/pkg/sentry/fs/inotify.go b/pkg/sentry/fs/inotify.go
index 928c90aa0..e3a715c1f 100644
--- a/pkg/sentry/fs/inotify.go
+++ b/pkg/sentry/fs/inotify.go
@@ -143,7 +143,10 @@ func (i *Inotify) Read(ctx context.Context, _ *File, dst usermem.IOSequence, _ i
}
var writeLen int64
- for event := i.events.Front(); event != nil; event = event.Next() {
+ for it := i.events.Front(); it != nil; {
+ event := it
+ it = it.Next()
+
// Does the buffer have enough remaining space to hold the event we're
// about to write out?
if dst.NumBytes() < int64(event.sizeOf()) {