mirror of
https://github.com/github/codeql.git
synced 2026-06-19 11:51:08 +02:00
Fix FP for py/file-not-closed
This commit is contained in:
@@ -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 |
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user