From 3d7838593bb7b196e39f93eb6457ff9ef2ffbb5a Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 27 Sep 2012 19:38:59 +0100 Subject: Issue #16060: Fix a double DECREF in int() implementation. Thanks Serhiy Storchaka. --- Misc/NEWS | 3 +++ Objects/abstract.c | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 6922b25..314b5a6 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ Core and Builtins - Issue #16046: Fix loading sourceless legacy .pyo files. +- Issue #16060: Fix refcounting bug when __trunc__ returns an object + whose __int__ gives a non-integer. Patch by Serhiy Storchaka. + Library ------- diff --git a/Objects/abstract.c b/Objects/abstract.c index ed5e196..a2737dd 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1228,11 +1228,10 @@ convert_integral_to_int(PyObject *integral, const char *error_format) nb = Py_TYPE(integral)->tp_as_number; if (nb->nb_int) { PyObject *as_int = nb->nb_int(integral); - Py_DECREF(integral); - if (!as_int) - return NULL; - if (PyLong_Check(as_int)) + if (!as_int || PyLong_Check(as_int)) { + Py_DECREF(integral); return as_int; + } Py_DECREF(as_int); } PyErr_Format(PyExc_TypeError, error_format, Py_TYPE(integral)->tp_name); -- cgit v0.12