Skip to content

Commit 68a8ca6

Browse files
gh-101819: Harden _io init (#104352)
Fix potential refleak if PyModule_AddObject() fails.
1 parent 22f3425 commit 68a8ca6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Modules/_io/_iomodule.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,11 @@ PyInit__io(void)
730730
"UnsupportedOperation", PyExc_OSError, PyExc_ValueError);
731731
if (state->unsupported_operation == NULL)
732732
goto fail;
733-
if (PyModule_AddObject(m, "UnsupportedOperation",
734-
Py_NewRef(state->unsupported_operation)) < 0)
733+
if (PyModule_AddObjectRef(m, "UnsupportedOperation",
734+
state->unsupported_operation) < 0)
735+
{
735736
goto fail;
737+
}
736738

737739
/* BlockingIOError, for compatibility */
738740
if (PyModule_AddObjectRef(m, "BlockingIOError",
@@ -785,7 +787,6 @@ PyInit__io(void)
785787
return m;
786788

787789
fail:
788-
Py_XDECREF(state->unsupported_operation);
789790
Py_DECREF(m);
790791
return NULL;
791792
}

0 commit comments

Comments
 (0)