]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
fix potential refleak in PyFloat_AsDouble (closes #23590)
authorBenjamin Peterson <benjamin@python.org>
Fri, 6 Mar 2015 14:08:44 +0000 (09:08 -0500)
committerBenjamin Peterson <benjamin@python.org>
Fri, 6 Mar 2015 14:08:44 +0000 (09:08 -0500)
Lib/test/test_float.py
Objects/floatobject.c

index e6779c4256ad083c4b22b3efe531676aad0029b4..5bf1d314e910edd1447469c82abe35349c1006cc 100644 (file)
@@ -8,6 +8,7 @@ import operator
 import random
 import fractions
 import sys
+import time
 
 INF = float("inf")
 NAN = float("nan")
@@ -164,6 +165,11 @@ class GeneralFloatCases(unittest.TestCase):
         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())
index 2bec0fbc6ffa726ee61d721e396422d12b0abd08..0ce7f6ce5cf22b89c798995b5beab4ce7d9b97e1 100644 (file)
@@ -271,6 +271,7 @@ PyFloat_AsDouble(PyObject *op)
     if (fo == NULL)
         return -1;
     if (!PyFloat_Check(fo)) {
+        Py_DECREF(fo);
         PyErr_SetString(PyExc_TypeError,
                         "nb_float should return float object");
         return -1;