11#include "Python.h"
2- #include "pycore_dict.h" // _PyDict_GetItemStringWithError()
32#include "pycore_fileutils.h" // _Py_HasFileSystemDefaultEncodeErrors
43#include "pycore_getopt.h" // _PyOS_GetOpt()
54#include "pycore_initconfig.h" // _PyStatus_OK()
@@ -1065,8 +1064,11 @@ _PyConfig_AsDict(const PyConfig *config)
10651064static PyObject *
10661065config_dict_get (PyObject * dict , const char * name )
10671066{
1068- PyObject * item = _PyDict_GetItemStringWithError (dict , name );
1069- if (item == NULL && !PyErr_Occurred ()) {
1067+ PyObject * item ;
1068+ if (PyDict_GetItemStringRef (dict , name , & item ) < 0 ) {
1069+ return NULL ;
1070+ }
1071+ if (item == NULL ) {
10701072 PyErr_Format (PyExc_ValueError , "missing config key: %s" , name );
10711073 return NULL ;
10721074 }
@@ -1096,6 +1098,7 @@ config_dict_get_int(PyObject *dict, const char *name, int *result)
10961098 return -1 ;
10971099 }
10981100 int value = _PyLong_AsInt (item );
1101+ Py_DECREF (item );
10991102 if (value == -1 && PyErr_Occurred ()) {
11001103 if (PyErr_ExceptionMatches (PyExc_TypeError )) {
11011104 config_dict_invalid_type (name );
@@ -1118,6 +1121,7 @@ config_dict_get_ulong(PyObject *dict, const char *name, unsigned long *result)
11181121 return -1 ;
11191122 }
11201123 unsigned long value = PyLong_AsUnsignedLong (item );
1124+ Py_DECREF (item );
11211125 if (value == (unsigned long )-1 && PyErr_Occurred ()) {
11221126 if (PyErr_ExceptionMatches (PyExc_TypeError )) {
11231127 config_dict_invalid_type (name );
@@ -1140,27 +1144,33 @@ config_dict_get_wstr(PyObject *dict, const char *name, PyConfig *config,
11401144 if (item == NULL ) {
11411145 return -1 ;
11421146 }
1147+
11431148 PyStatus status ;
11441149 if (item == Py_None ) {
11451150 status = PyConfig_SetString (config , result , NULL );
11461151 }
11471152 else if (!PyUnicode_Check (item )) {
11481153 config_dict_invalid_type (name );
1149- return -1 ;
1154+ goto error ;
11501155 }
11511156 else {
11521157 wchar_t * wstr = PyUnicode_AsWideCharString (item , NULL );
11531158 if (wstr == NULL ) {
1154- return -1 ;
1159+ goto error ;
11551160 }
11561161 status = PyConfig_SetString (config , result , wstr );
11571162 PyMem_Free (wstr );
11581163 }
11591164 if (_PyStatus_EXCEPTION (status )) {
11601165 PyErr_NoMemory ();
1161- return -1 ;
1166+ goto error ;
11621167 }
1168+ Py_DECREF (item );
11631169 return 0 ;
1170+
1171+ error :
1172+ Py_DECREF (item );
1173+ return -1 ;
11641174}
11651175
11661176
@@ -1174,6 +1184,7 @@ config_dict_get_wstrlist(PyObject *dict, const char *name, PyConfig *config,
11741184 }
11751185
11761186 if (!PyList_CheckExact (list )) {
1187+ Py_DECREF (list );
11771188 config_dict_invalid_type (name );
11781189 return -1 ;
11791190 }
@@ -1207,10 +1218,12 @@ config_dict_get_wstrlist(PyObject *dict, const char *name, PyConfig *config,
12071218 goto error ;
12081219 }
12091220 _PyWideStringList_Clear (& wstrlist );
1221+ Py_DECREF (list );
12101222 return 0 ;
12111223
12121224error :
12131225 _PyWideStringList_Clear (& wstrlist );
1226+ Py_DECREF (list );
12141227 return -1 ;
12151228}
12161229
0 commit comments