mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
SF patch 703666: Several objects don't decref tmp on failure in subtype_new
Submitted By: Christopher A. Craig Fillin some missing decrefs.
This commit is contained in:
parent
6891cd3aa3
commit
f466793fcc
4 changed files with 13 additions and 4 deletions
|
@ -751,8 +751,10 @@ float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return NULL;
|
return NULL;
|
||||||
assert(PyFloat_CheckExact(tmp));
|
assert(PyFloat_CheckExact(tmp));
|
||||||
new = type->tp_alloc(type, 0);
|
new = type->tp_alloc(type, 0);
|
||||||
if (new == NULL)
|
if (new == NULL) {
|
||||||
|
Py_DECREF(tmp);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
((PyFloatObject *)new)->ob_fval = ((PyFloatObject *)tmp)->ob_fval;
|
((PyFloatObject *)new)->ob_fval = ((PyFloatObject *)tmp)->ob_fval;
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
return new;
|
return new;
|
||||||
|
|
|
@ -958,8 +958,10 @@ int_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
}
|
}
|
||||||
|
|
||||||
new = type->tp_alloc(type, 0);
|
new = type->tp_alloc(type, 0);
|
||||||
if (new == NULL)
|
if (new == NULL) {
|
||||||
|
Py_DECREF(tmp);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
((PyIntObject *)new)->ob_ival = ival;
|
((PyIntObject *)new)->ob_ival = ival;
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
return new;
|
return new;
|
||||||
|
|
|
@ -2794,8 +2794,10 @@ long_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
n = -n;
|
n = -n;
|
||||||
new = (PyLongObject *)type->tp_alloc(type, n);
|
new = (PyLongObject *)type->tp_alloc(type, n);
|
||||||
if (new == NULL)
|
if (new == NULL) {
|
||||||
|
Py_DECREF(tmp);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
assert(PyLong_Check(new));
|
assert(PyLong_Check(new));
|
||||||
new->ob_size = tmp->ob_size;
|
new->ob_size = tmp->ob_size;
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
|
|
|
@ -6688,12 +6688,15 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return NULL;
|
return NULL;
|
||||||
assert(PyUnicode_Check(tmp));
|
assert(PyUnicode_Check(tmp));
|
||||||
pnew = (PyUnicodeObject *) type->tp_alloc(type, n = tmp->length);
|
pnew = (PyUnicodeObject *) type->tp_alloc(type, n = tmp->length);
|
||||||
if (pnew == NULL)
|
if (pnew == NULL) {
|
||||||
|
Py_DECREF(tmp);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
pnew->str = PyMem_NEW(Py_UNICODE, n+1);
|
pnew->str = PyMem_NEW(Py_UNICODE, n+1);
|
||||||
if (pnew->str == NULL) {
|
if (pnew->str == NULL) {
|
||||||
_Py_ForgetReference((PyObject *)pnew);
|
_Py_ForgetReference((PyObject *)pnew);
|
||||||
PyObject_Del(pnew);
|
PyObject_Del(pnew);
|
||||||
|
Py_DECREF(tmp);
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
Py_UNICODE_COPY(pnew->str, tmp->str, n+1);
|
Py_UNICODE_COPY(pnew->str, tmp->str, n+1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue