mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
GH-98897: fix memory leak if math.dist
raises exception (GH-98898)
(cherry picked from commit ab57505070
)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
parent
46a3cf4fe3
commit
8495af8963
3 changed files with 9 additions and 3 deletions
|
@ -1006,6 +1006,11 @@ class MathTests(unittest.TestCase):
|
|||
self.assertEqual(math.dist(p, q), 5*scale)
|
||||
self.assertEqual(math.dist(q, p), 5*scale)
|
||||
|
||||
def test_math_dist_leak(self):
|
||||
# gh-98897: Check for error handling does not leak memory
|
||||
with self.assertRaises(ValueError):
|
||||
math.dist([1, 2], [3, 4, 5])
|
||||
|
||||
def testIsqrt(self):
|
||||
# Test a variety of inputs, large and small.
|
||||
test_values = (
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix memory leak in :func:`math.dist` when both points don't have the same dimension. Patch by Kumar Aditya.
|
|
@ -2703,13 +2703,13 @@ math_dist_impl(PyObject *module, PyObject *p, PyObject *q)
|
|||
if (m != n) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"both points must have the same number of dimensions");
|
||||
return NULL;
|
||||
|
||||
goto error_exit;
|
||||
}
|
||||
if (n > NUM_STACK_ELEMS) {
|
||||
diffs = (double *) PyObject_Malloc(n * sizeof(double));
|
||||
if (diffs == NULL) {
|
||||
return PyErr_NoMemory();
|
||||
PyErr_NoMemory();
|
||||
goto error_exit;
|
||||
}
|
||||
}
|
||||
for (i=0 ; i<n ; i++) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue