test/exhaustive: fix file handle leak in get_pipe_rw

Use 'with' statement for opening /proc fdinfo to ensure the
file handle is closed after iteration.

Assisted-by: Claude Code (claude-opus-4-6)
Signed-off-by: Adrian Reber <areber@redhat.com>
This commit is contained in:
Adrian Reber 2026-07-06 13:33:06 +00:00 committed by Radostin Stoyanov
parent 0530651cad
commit 1f78f31bcd

View file

@ -61,14 +61,15 @@ def get_pipe_ino(pid, fd):
def get_pipe_rw(pid, fd):
for l in open('/proc/%d/fdinfo/%d' % (pid, fd)):
if l.startswith('flags:'):
f = l.split(None, 1)[1][-2]
if f == '0':
return 0 # Read
elif f == '1':
return 1 # Write
break
with open('/proc/%d/fdinfo/%d' % (pid, fd)) as fh:
for l in fh:
if l.startswith('flags:'):
f = l.split(None, 1)[1][-2]
if f == '0':
return 0 # Read
elif f == '1':
return 1 # Write
break
raise Exception('Unexpected fdinfo contents')