Visitar URL original
gh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing by colorfulappl · Pull Request #99890 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Reset pointer to NULL when memory is freed
  • Loading branch information
colorfulappl committed Nov 30, 2022
commit 9271e851ef23f9288bdbbcf578dbc723ebae7dd5
10 changes: 6 additions & 4 deletions Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ _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;
if (*pptr) {
Comment thread
colorfulappl marked this conversation as resolved.
Outdated
PyMem_Free(*pptr);
*pptr = NULL;
}
return 0;
}
Expand Down Expand Up @@ -1116,7 +1118,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)",
Expand Down Expand Up @@ -1162,7 +1164,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);
Expand Down