summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-11-01 02:40:30 (GMT)
committerGitHub <noreply@github.com>2022-11-01 02:40:30 (GMT)
commit8495af8963234aa1c6fe34846e9552a79eaac7af (patch)
treecbd3a2e3aeba3719b430dcb255b4fde5ee88b2ef /Modules
parent46a3cf4fe3380b5d4560589cce8f602ba949832d (diff)
downloadcpython-8495af8963234aa1c6fe34846e9552a79eaac7af.zip
cpython-8495af8963234aa1c6fe34846e9552a79eaac7af.tar.gz
cpython-8495af8963234aa1c6fe34846e9552a79eaac7af.tar.bz2
GH-98897: fix memory leak if `math.dist` raises exception (GH-98898)
(cherry picked from commit ab575050709e2b313ca9a9585f09b6f4b0560318) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/mathmodule.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index aa93e75..0a907a0 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -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++) {