diff options
author | colorfulappl <colorfulappl@qq.com> | 2022-12-21 10:03:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-21 10:03:21 (GMT) |
commit | 591365cd49cf1065e27bb1358aa5f07bd854dd33 (patch) | |
tree | 8fa3c5c55610faea7c3b6d9064365106a5498c0d /Python | |
parent | 919045cb73709a3933ec807c09b929c7ad7f02f4 (diff) | |
download | cpython-591365cd49cf1065e27bb1358aa5f07bd854dd33.zip cpython-591365cd49cf1065e27bb1358aa5f07bd854dd33.tar.gz cpython-591365cd49cf1065e27bb1358aa5f07bd854dd33.tar.bz2 |
[3.10] gh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (GH-99890) (#100386)
(cherry picked from commit efbb1eb9f54cad4f7bf5df03eed3a6aba02d99f4)
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.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index fd49ee0..3b65cfa 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -201,9 +201,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; } @@ -1168,7 +1168,7 @@ _Py_COMP_DIAG_POP PyErr_NoMemory(); RETURN_ERR_OCCURRED; } - if (addcleanup(*buffer, freelist, cleanup_ptr)) { + if (addcleanup(buffer, freelist, cleanup_ptr)) { Py_DECREF(s); return converterr( "(cleanup problem)", @@ -1214,7 +1214,7 @@ _Py_COMP_DIAG_POP 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); |