gh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing by colorfulappl · Pull Request #99890 · python/cpython
Conversation
In the family of _PyArg_Parse functions, pointers can be passed in as arguments to store the parsed PyArgs.
If a pointer is assigned to newly allocated memory and the memory is freed as a result of an error while parsing the subsequent PyArgs, the pointer should be set to NULL; otherwise, it leaks the freed memory.
This fix corresponds to my comment in #99240
If function _PyArg_ParseStack parses failed, assign all the parsed arguments to "NULL" after they are freed, this should be done in _PyArg_ParseStack.
carljm
changed the title
gh-99240: Reset pointer to NULL then the pointed memory is freed in argument parsing
gh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, @colorfulappl and @kumaraditya303, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker a6f82f1fc68cb24e2d88d35fde4cfb663213a744 3.11
Sorry, @colorfulappl and @kumaraditya303, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker a6f82f1fc68cb24e2d88d35fde4cfb663213a744 3.10
kumaraditya303 added a commit to kumaraditya303/cpython that referenced this pull request
…d in argument parsing (python#99890) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@colorfulappl Can you create the backport PRs?
Sure. I will do this later.
colorfulappl added a commit to colorfulappl/cpython that referenced this pull request
…is freed in argument parsing (pythonGH-99890) (cherry picked from commit efbb1eb) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
colorfulappl added a commit to colorfulappl/cpython that referenced this pull request
…is freed in argument parsing (pythonGH-99890) (cherry picked from commit efbb1eb) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
kumaraditya303 added a commit that referenced this pull request
kumaraditya303 added a commit that referenced this pull request
rwgk pushed a commit to rwgk/cpython that referenced this pull request
…d in argument parsing (python#99890) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>