mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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>
This commit is contained in:
parent
9cdd2fa63b
commit
efbb1eb9f5
4 changed files with 30 additions and 5 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue