diff options
author | Erlend E. Aasland <erlend.aasland@protonmail.com> | 2023-05-10 10:59:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-10 10:59:03 (GMT) |
commit | 68a8ca6dc10bdceb4efaac569081b78ec01c3a99 (patch) | |
tree | 211d6ecac970cbe53024c98f31e6439e3e03b18b /Modules/_io | |
parent | 22f3425c3d3d896be0917d80d55e8abb08d99b18 (diff) | |
download | cpython-68a8ca6dc10bdceb4efaac569081b78ec01c3a99.zip cpython-68a8ca6dc10bdceb4efaac569081b78ec01c3a99.tar.gz cpython-68a8ca6dc10bdceb4efaac569081b78ec01c3a99.tar.bz2 |
gh-101819: Harden _io init (#104352)
Fix potential refleak if PyModule_AddObject() fails.
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/_iomodule.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index c05407b..6c5ea28 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -730,9 +730,11 @@ PyInit__io(void) "UnsupportedOperation", PyExc_OSError, PyExc_ValueError); if (state->unsupported_operation == NULL) goto fail; - if (PyModule_AddObject(m, "UnsupportedOperation", - Py_NewRef(state->unsupported_operation)) < 0) + if (PyModule_AddObjectRef(m, "UnsupportedOperation", + state->unsupported_operation) < 0) + { goto fail; + } /* BlockingIOError, for compatibility */ if (PyModule_AddObjectRef(m, "BlockingIOError", @@ -785,7 +787,6 @@ PyInit__io(void) return m; fail: - Py_XDECREF(state->unsupported_operation); Py_DECREF(m); return NULL; } |