summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-11-01 02:18:32 (GMT)
committerGitHub <noreply@github.com>2022-11-01 02:18:32 (GMT)
commitab575050709e2b313ca9a9585f09b6f4b0560318 (patch)
treeea50310d73da93ffad36bfeab28f760ed1926849 /Modules
parent88297e2a8a75898228360ee369628a4a6111e2ee (diff)
downloadcpython-ab575050709e2b313ca9a9585f09b6f4b0560318.zip
cpython-ab575050709e2b313ca9a9585f09b6f4b0560318.tar.gz
cpython-ab575050709e2b313ca9a9585f09b6f4b0560318.tar.bz2
GH-98897: fix memory leak if `math.dist` raises exception (GH-98898)
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 48625c8..4642787 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -2717,13 +2717,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++) {