Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-110572: Fix leaks in test_*_code in _testcapi/getargs.c#110573
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 our terms of service and privacy 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 from all commits
Commits
File 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
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 |
|---|---|---|
| @@ -333,68 +333,83 @@ getargs_K(PyObject *self, PyObject *args) | ||
| static PyObject * | ||
| test_k_code(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||
| { | ||
| PyObject *tuple, *num; | ||
| unsigned long value; | ||
| tuple = PyTuple_New(1); | ||
| PyObject *tuple = PyTuple_New(1); | ||
| if (tuple == NULL){ | ||
| return NULL; | ||
| } | ||
| /* a number larger than ULONG_MAX even on 64-bit platforms */ | ||
| num = PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16); | ||
| PyObject *num = PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16); | ||
| if (num == NULL){ | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| value = PyLong_AsUnsignedLongMask(num); | ||
| if (value != ULONG_MAX){ | ||
| unsigned long value = PyLong_AsUnsignedLongMask(num); | ||
| if (value == (unsigned long)-1 && PyErr_Occurred()){ | ||
| Py_DECREF(num); | ||
| goto error; | ||
| } | ||
| else if (value != ULONG_MAX){ | ||
| Py_DECREF(num); | ||
| PyErr_SetString(PyExc_AssertionError, | ||
| "test_k_code: " | ||
| "PyLong_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF"); | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| PyTuple_SET_ITEM(tuple, 0, num); | ||
| value = 0; | ||
| if (!PyArg_ParseTuple(tuple, "k:test_k_code", &value)){ | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| if (value != ULONG_MAX){ | ||
| PyErr_SetString(PyExc_AssertionError, | ||
| "test_k_code: k code returned wrong value for long 0xFFF...FFF"); | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| Py_DECREF(num); | ||
| Py_DECREF(tuple); // also clears `num` | ||
| tuple = PyTuple_New(1); | ||
| if (tuple == NULL){ | ||
| return NULL; | ||
| } | ||
serhiy-storchaka marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| num = PyLong_FromString("-FFFFFFFF000000000000000042", NULL, 16); | ||
| if (num == NULL){ | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| value = PyLong_AsUnsignedLongMask(num); | ||
| if (value != (unsigned long)-0x42){ | ||
| if (value == (unsigned long)-1 && PyErr_Occurred()){ | ||
| Py_DECREF(num); | ||
| goto error; | ||
| } | ||
| else if (value != (unsigned long)-0x42){ | ||
| Py_DECREF(num); | ||
| PyErr_SetString(PyExc_AssertionError, | ||
| "test_k_code: " | ||
| "PyLong_AsUnsignedLongMask() returned wrong value for long -0xFFF..000042"); | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| PyTuple_SET_ITEM(tuple, 0, num); | ||
| value = 0; | ||
| if (!PyArg_ParseTuple(tuple, "k:test_k_code", &value)){ | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| if (value != (unsigned long)-0x42){ | ||
| PyErr_SetString(PyExc_AssertionError, | ||
| "test_k_code: k code returned wrong value for long -0xFFF..000042"); | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| Py_DECREF(tuple); | ||
| Py_RETURN_NONE; | ||
| error: | ||
| Py_DECREF(tuple); | ||
| return NULL; | ||
| } | ||
| static PyObject * | ||
| @@ -684,51 +699,56 @@ getargs_et_hash(PyObject *self, PyObject *args) | ||
| static PyObject * | ||
| test_L_code(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||
| { | ||
| PyObject *tuple, *num; | ||
| long long value; | ||
| tuple = PyTuple_New(1); | ||
| PyObject *tuple = PyTuple_New(1); | ||
| if (tuple == NULL){ | ||
| return NULL; | ||
| } | ||
| num = PyLong_FromLong(42); | ||
| PyObject *num = PyLong_FromLong(42); | ||
| if (num == NULL){ | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| PyTuple_SET_ITEM(tuple, 0, num); | ||
| value = -1; | ||
| long long value = -1; | ||
| if (!PyArg_ParseTuple(tuple, "L:test_L_code", &value)){ | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| if (value != 42){ | ||
| PyErr_SetString(PyExc_AssertionError, | ||
| "test_L_code: L code returned wrong value for long 42"); | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| Py_DECREF(num); | ||
| Py_DECREF(tuple); // also clears `num` | ||
| tuple = PyTuple_New(1); | ||
| if (tuple == NULL){ | ||
| return NULL; | ||
| } | ||
| num = PyLong_FromLong(42); | ||
| if (num == NULL){ | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| PyTuple_SET_ITEM(tuple, 0, num); | ||
| value = -1; | ||
| if (!PyArg_ParseTuple(tuple, "L:test_L_code", &value)){ | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| if (value != 42){ | ||
| PyErr_SetString(PyExc_AssertionError, | ||
| "test_L_code: L code returned wrong value for int 42"); | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| Py_DECREF(tuple); | ||
| Py_RETURN_NONE; | ||
| error: | ||
| Py_DECREF(tuple); | ||
| return NULL; | ||
| } | ||
| /* Test the s and z codes for PyArg_ParseTuple. | ||
| @@ -745,7 +765,7 @@ test_s_code(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||
| PyObject *obj = PyUnicode_Decode("t\xeate", strlen("t\xeate"), | ||
| "latin-1", NULL); | ||
| if (obj == NULL){ | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| PyTuple_SET_ITEM(tuple, 0, obj); | ||
| @@ -755,15 +775,19 @@ test_s_code(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||
| */ | ||
| char *value; | ||
| if (!PyArg_ParseTuple(tuple, "s:test_s_code1", &value)){ | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| if (!PyArg_ParseTuple(tuple, "z:test_s_code2", &value)){ | ||
| return NULL; | ||
| goto error; | ||
| } | ||
| Py_DECREF(tuple); | ||
| Py_RETURN_NONE; | ||
| error: | ||
| Py_DECREF(tuple); | ||
| return NULL; | ||
| } | ||
| static PyObject * | ||
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.
Uh oh!
There was an error while loading. Please reload this page.