diff options
author | Benjamin Peterson <benjamin@python.org> | 2015-03-06 14:08:44 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2015-03-06 14:08:44 (GMT) |
commit | f050648a505b3810b659ca490c2e418a02c702cc (patch) | |
tree | c517105ffc9b5bcfcadf13d626cf795d6b4b533e | |
parent | 8c51fedcdffcdca46eb7420325cf69c1da2d30be (diff) | |
download | cpython-f050648a505b3810b659ca490c2e418a02c702cc.zip cpython-f050648a505b3810b659ca490c2e418a02c702cc.tar.gz cpython-f050648a505b3810b659ca490c2e418a02c702cc.tar.bz2 |
fix potential refleak in PyFloat_AsDouble (closes #23590)
-rw-r--r-- | Lib/test/test_float.py | 6 | ||||
-rw-r--r-- | Objects/floatobject.c | 1 |
2 files changed, 7 insertions, 0 deletions
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 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()) 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 @@ 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; |