Fix FP for py/file-not-closed

This commit is contained in:
Owen Mansel-Chan
2026-06-17 12:36:04 +01:00
parent 890969433f
commit 199fd864ad
3 changed files with 33 additions and 7 deletions

View File

@@ -7,4 +7,3 @@
| resources_test.py:250:11:250:25 | ControlFlowNode for open() | File is opened but is not closed. | file://:0:0:0:0 | (none) | this operation |
| resources_test.py:271:10:271:27 | ControlFlowNode for Attribute() | File may not be closed if $@ raises an exception. | resources_test.py:273:5:273:19 | ControlFlowNode for Attribute() | this operation |
| resources_test.py:287:11:287:20 | ControlFlowNode for open() | File may not be closed if $@ raises an exception. | resources_test.py:289:5:289:31 | ControlFlowNode for Attribute() | this operation |
| resources_test.py:361:13:361:27 | ControlFlowNode for Attribute() | File is opened but is not closed. | file://:0:0:0:0 | (none) | this operation |

View File

@@ -350,14 +350,14 @@ class FdHolder33():
os.close(self._fd)
def closed33(path):
# False positive mirroring CPython's `_pyio.open`.
# Regression test mirroring CPython's `_pyio.open`.
# `holder.fileno()` merely returns the existing file descriptor; it does not
# open a new resource. With instance-attribute type tracking, the `os.open`
# source flows through `self._fd` and back out of `fileno()`, so the call
# `holder.fileno()` is wrongly treated as a fresh file-open whose result is
# never closed. The descriptor is in fact owned and closed by `holder.close()`.
# source flows through `self._fd` and back out of `fileno()`. The query must
# not treat that re-exposed descriptor as a fresh file-open whose result is
# never closed. The descriptor is owned and closed by `holder.close()`.
holder = FdHolder33(path)
try:
n = holder.fileno() # $ SPURIOUS: Alert
n = holder.fileno() # No alert: this re-exposes an existing descriptor, not a new open.
finally:
holder.close()