From a915723dc780f2c6753487795988fe3b75e140a9 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 6 Mar 2015 09:08:44 -0500 Subject: fix potential refleak in PyFloat_AsDouble (closes #23590) --- Lib/test/test_float.py | 6 ++++++ Objects/floatobject.c | 1 + 2 files changed, 7 insertions(+) diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index e1e1f04..bd2d6c3 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -6,6 +6,7 @@ from test import support import math from math import isinf, isnan, copysign, ldexp import operator +import time import random, fractions INF = float("inf") @@ -129,6 +130,11 @@ class GeneralFloatCases(unittest.TestCase): self.assertRaises(TypeError, float, Foo4(42)) 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 33e30ca..1dca947 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -220,6 +220,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; -- cgit v0.12