gh-106307: Fix PyMapping_GetOptionalItemString() (GH-108797)

The resulting pointer was not set to NULL if the creation of a temporary
string object was failed.

The tests were also missed due to oversight.
This commit is contained in:
Serhiy Storchaka 2023-09-06 22:47:38 +03:00 committed by GitHub
parent bf414b7fcb
commit 3a08db8d13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View file

@ -2393,11 +2393,13 @@ int
PyMapping_GetOptionalItemString(PyObject *obj, const char *key, PyObject **result)
{
if (key == NULL) {
*result = NULL;
null_error();
return -1;
}
PyObject *okey = PyUnicode_FromString(key);
if (okey == NULL) {
*result = NULL;
return -1;
}
int rc = PyMapping_GetOptionalItem(obj, okey, result);