Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing#99890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from6 commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
9271e85 Reset pointer to NULL when memory is freed
colorfulappleba62a3 Add news
colorfulappl39895ee Remove unnecessary null-check
colorfulapplef866b2 Add test
colorfulappl357576b Fix an error
colorfulappl0424701 PyMem_FREE -> PyMem_Free
kumaraditya3034a7d386 Update Modules/_testcapi/getargs.c
kumaraditya3031d3b069 Merge branch 'main' into clear_freed_pointer
kumaraditya3036e9744c Update Modules/_testcapi/getargs.c
erlend-aaslandFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletionsLib/test/test_capi/test_getargs.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletionsMisc/NEWS.d/next/C API/2022-11-30-16-39-22.gh-issue-99240.67nAX-.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| In argument parsing, after deallocating newly allocated memory, reset its | ||
| pointer to NULL. |
18 changes: 18 additions & 0 deletionsModules/_testcapi/getargs.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -854,6 +854,23 @@ getargs_s_hash_int2(PyObject *self, PyObject *args, PyObject *kwargs) | ||
| Py_RETURN_NONE; | ||
| } | ||
| static PyObject * | ||
| gh_99240_clear_args(PyObject *self, PyObject *args) { | ||
erlend-aasland marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| char *a = NULL; | ||
| char *b = NULL; | ||
| if (!PyArg_ParseTuple(args, "eses", "idna", &a, "idna", &b)) { | ||
| if (a || b) { | ||
| PyErr_Clear(); | ||
| PyErr_SetString(PyExc_AssertionError, "Arguments is not cleared."); | ||
kumaraditya303 marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| return NULL; | ||
| } | ||
| PyMem_Free(a); | ||
| PyMem_Free(b); | ||
| Py_RETURN_NONE; | ||
| } | ||
| static PyMethodDef test_methods[] = { | ||
| {"get_args", get_args, METH_VARARGS}, | ||
| {"get_kwargs", _PyCFunction_CAST(get_kwargs), METH_VARARGS|METH_KEYWORDS}, | ||
| @@ -906,6 +923,7 @@ static PyMethodDef test_methods[] = { | ||
| {"test_empty_argparse", test_empty_argparse, METH_NOARGS}, | ||
| {"test_k_code", test_k_code, METH_NOARGS}, | ||
| {"test_s_code", test_s_code, METH_NOARGS}, | ||
| {"gh_99240_clear_args", gh_99240_clear_args, METH_VARARGS}, | ||
| {NULL}, | ||
| }; | ||
10 changes: 5 additions & 5 deletionsPython/getargs.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.