Issue #15229: An OSError subclass whose __init__ doesn't call back

OSError.__init__ could produce incomplete instances, leading to crashes
when calling str() on them.
This commit is contained in:
Antoine Pitrou 2012-06-30 23:37:47 +02:00
parent 4c99071c9b
commit f87289bb58
3 changed files with 19 additions and 0 deletions

View file

@ -834,6 +834,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,
#endif
/* Steals the reference to args */
Py_CLEAR(self->args);
self->args = args;
args = NULL;
@ -916,6 +917,11 @@ OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
))
goto error;
}
else {
self->args = PyTuple_New(0);
if (self->args == NULL)
goto error;
}
return (PyObject *) self;