Commit a915723d authored by Benjamin Peterson's avatar Benjamin Peterson

fix potential refleak in PyFloat_AsDouble (closes #23590)

parent b5a23223
...@@ -6,6 +6,7 @@ from test import support ...@@ -6,6 +6,7 @@ from test import support
import math import math
from math import isinf, isnan, copysign, ldexp from math import isinf, isnan, copysign, ldexp
import operator import operator
import time
import random, fractions import random, fractions
INF = float("inf") INF = float("inf")
...@@ -129,6 +130,11 @@ class GeneralFloatCases(unittest.TestCase): ...@@ -129,6 +130,11 @@ class GeneralFloatCases(unittest.TestCase):
self.assertRaises(TypeError, float, Foo4(42)) self.assertRaises(TypeError, float, Foo4(42))
self.assertAlmostEqual(float(FooStr('8')), 9.) self.assertAlmostEqual(float(FooStr('8')), 9.)
class Foo5:
def __float__(self):
return ""
self.assertRaises(TypeError, time.sleep, Foo5())
def test_is_integer(self): def test_is_integer(self):
self.assertFalse((1.1).is_integer()) self.assertFalse((1.1).is_integer())
self.assertTrue((1.).is_integer()) self.assertTrue((1.).is_integer())
......
...@@ -220,6 +220,7 @@ PyFloat_AsDouble(PyObject *op) ...@@ -220,6 +220,7 @@ PyFloat_AsDouble(PyObject *op)
if (fo == NULL) if (fo == NULL)
return -1; return -1;
if (!PyFloat_Check(fo)) { if (!PyFloat_Check(fo)) {
Py_DECREF(fo);
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"nb_float should return float object"); "nb_float should return float object");
return -1; return -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment