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:
Miss Islington (bot) 2022-10-31 19:47:29 -07:00 committed by GitHub
parent d3d1738acd
commit 078ce6891c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View file

@ -2658,13 +2658,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++) {