fix potential refleak in PyFloat_AsDouble (closes #23590)
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index e6779c4..5bf1d31 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -8,6 +8,7 @@
import random
import fractions
import sys
+import time
INF = float("inf")
NAN = float("nan")
@@ -164,6 +165,11 @@
self.assertAlmostEqual(float(FooUnicode('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):
self.assertFalse((1.1).is_integer())
self.assertTrue((1.).is_integer())
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 2bec0fb..0ce7f6c 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -271,6 +271,7 @@
if (fo == NULL)
return -1;
if (!PyFloat_Check(fo)) {
+ Py_DECREF(fo);
PyErr_SetString(PyExc_TypeError,
"nb_float should return float object");
return -1;