diff options
author | colorfulappl <colorfulappl@qq.com> | 2022-12-21 18:02:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-21 15:32:29 +0530 |
commit | bed1d141a95e8d69f522e6f4e46e0647c68a2460 (patch) | |
tree | 86a8bd1afbb6e05ceeabf2a96790d7c73f5a3cf0 /Python | |
parent | bee905184e9297e58d421ecfee556277dc01864d (diff) | |
download | cpython3-bed1d141a95e8d69f522e6f4e46e0647c68a2460.tar.gz |
[3.11] gh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (GH-99890) (#100385)
(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 c3e3cf155b..9d6483f4fe 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; } @@ -1169,7 +1169,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)", @@ -1215,7 +1215,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); |