Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 46ef319

Browse files
committed
Issue #19429, #19437: fix error handling in the OSError constructor
1 parent b031427 commit 46ef319

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Objects/exceptions.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,
845845
/* Steals the reference to args */
846846
Py_CLEAR(self->args);
847847
self->args = args;
848-
args = NULL;
848+
*p_args = args = NULL;
849849

850850
return 0;
851851
}
@@ -885,11 +885,12 @@ OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
885885
PyObject *winerror = NULL;
886886
#endif
887887

888+
Py_INCREF(args);
889+
888890
if (!oserror_use_init(type)) {
889891
if (!_PyArg_NoKeywords(type->tp_name, kwds))
890-
return NULL;
892+
goto error;
891893

892-
Py_INCREF(args);
893894
if (oserror_parse_args(&args, &myerrno, &strerror, &filename
894895
#ifdef MS_WINDOWS
895896
, &winerror
@@ -932,6 +933,7 @@ OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
932933
goto error;
933934
}
934935

936+
Py_XDECREF(args);
935937
return (PyObject *) self;
936938

937939
error:

0 commit comments

Comments
 (0)