mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-18 00:58:31 +00:00
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:
parent
0530651cad
commit
1f78f31bcd
1 changed files with 9 additions and 8 deletions
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue