summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorcolorfulappl <colorfulappl@qq.com>2022-12-17 06:37:44 (GMT)
committerGitHub <noreply@github.com>2022-12-17 06:37:44 (GMT)
commitefbb1eb9f54cad4f7bf5df03eed3a6aba02d99f4 (patch)
treee33a76ccf9dfad64e82d08d073d86706152758b2 /Python
parent9cdd2fa63b7549d00830bccf19a34e9d69d0b15e (diff)
downloadcpython-efbb1eb9f54cad4f7bf5df03eed3a6aba02d99f4.zip
cpython-efbb1eb9f54cad4f7bf5df03eed3a6aba02d99f4.tar.gz
cpython-efbb1eb9f54cad4f7bf5df03eed3a6aba02d99f4.tar.bz2
gh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (#99890)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/getargs.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 0167dd7..66dd908 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -202,9 +202,9 @@ _PyArg_VaParse_SizeT(PyObject *args, const char *format, va_list va)
static int
cleanup_ptr(PyObject *self, void *ptr)
{
- if (ptr) {
- PyMem_Free(ptr);
- }
+ void **pptr = (void **)ptr;
+ PyMem_Free(*pptr);
+ *pptr = NULL;
return 0;
}
@@ -1116,7 +1116,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
PyErr_NoMemory();
RETURN_ERR_OCCURRED;
}
- if (addcleanup(*buffer, freelist, cleanup_ptr)) {
+ if (addcleanup(buffer, freelist, cleanup_ptr)) {
Py_DECREF(s);
return converterr(
"(cleanup problem)",
@@ -1162,7 +1162,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
PyErr_NoMemory();
RETURN_ERR_OCCURRED;
}
- if (addcleanup(*buffer, freelist, cleanup_ptr)) {
+ if (addcleanup(buffer, freelist, cleanup_ptr)) {
Py_DECREF(s);
return converterr("(cleanup problem)",
arg, msgbuf, bufsize);