@@ -1207,13 +1207,16 @@ static int CPyImport_InitSpecClasses(void) {
12071207 Py_CLEAR (CPyImport_ExtFileLoaderClass );
12081208 return -1 ;
12091209 }
1210- CPyImport_SpecKwnames = PyTuple_Pack (2 ,
1211- PyUnicode_InternFromString ("origin" ),
1212- PyUnicode_InternFromString ("is_package" ));
1210+ PyObject * origin_str = PyUnicode_InternFromString ("origin" );
1211+ PyObject * is_package_str = PyUnicode_InternFromString ("is_package" );
1212+ if (origin_str == NULL || is_package_str == NULL ) {
1213+ CPyError_OutOfMemory ();
1214+ }
1215+ CPyImport_SpecKwnames = PyTuple_Pack (2 , origin_str , is_package_str );
1216+ Py_DECREF (origin_str );
1217+ Py_DECREF (is_package_str );
12131218 if (CPyImport_SpecKwnames == NULL ) {
1214- Py_CLEAR (CPyImport_ModuleSpecClass );
1215- Py_CLEAR (CPyImport_ExtFileLoaderClass );
1216- return -1 ;
1219+ CPyError_OutOfMemory ();
12171220 }
12181221 return 0 ;
12191222}
@@ -1258,9 +1261,7 @@ static int CPyImport_SetModuleFile(PyObject *modobj, PyObject *module_name,
12581261 PyObject * dot_str = PyUnicode_FromString ("." );
12591262 PyObject * sep_str = PyUnicode_FromOrdinal (sep_char );
12601263 if (dot_str == NULL || sep_str == NULL ) {
1261- Py_XDECREF (dot_str );
1262- Py_XDECREF (sep_str );
1263- return -1 ;
1264+ CPyError_OutOfMemory ();
12641265 }
12651266 PyObject * module_path = PyUnicode_Replace (module_name , dot_str , sep_str , -1 );
12661267 Py_DECREF (dot_str );
@@ -1331,8 +1332,7 @@ static int CPyImport_SetModulePath(PyObject *modobj) {
13311332 }
13321333 PyObject * path_list = PyList_New (1 );
13331334 if (path_list == NULL ) {
1334- Py_DECREF (dir );
1335- return -1 ;
1335+ CPyError_OutOfMemory ();
13361336 }
13371337 PyList_SET_ITEM (path_list , 0 , dir ); // steals ref to dir
13381338 int rc = PyObject_SetAttrString (modobj , "__path__" , path_list );
@@ -1425,12 +1425,11 @@ PyObject *CPyImport_ImportNative(PyObject *module_name,
14251425 // Import the parent package first to preserve import ordering semantics.
14261426 PyObject * parent_name = PyUnicode_Substring (module_name , 0 , dot );
14271427 if (parent_name == NULL ) {
1428- return NULL ;
1428+ CPyError_OutOfMemory () ;
14291429 }
14301430 child_name = PyUnicode_Substring (module_name , dot + 1 , name_len );
14311431 if (child_name == NULL ) {
1432- Py_DECREF (parent_name );
1433- return NULL ;
1432+ CPyError_OutOfMemory ();
14341433 }
14351434 parent_module = PyImport_Import (parent_name );
14361435 Py_DECREF (parent_name );
@@ -1509,10 +1508,12 @@ PyObject *CPyImport_ImportNative(PyObject *module_name,
15091508 package_name = PyUnicode_Substring (module_name , 0 , dot );
15101509 } else {
15111510 package_name = PyUnicode_FromString ("" );
1511+ if (package_name == NULL ) {
1512+ CPyError_OutOfMemory ();
1513+ }
15121514 }
1513- if (package_name == NULL ||
1514- PyObject_SetAttrString (modobj , "__package__" , package_name ) < 0 ) {
1515- Py_XDECREF (package_name );
1515+ if (PyObject_SetAttrString (modobj , "__package__" , package_name ) < 0 ) {
1516+ Py_DECREF (package_name );
15161517 goto fail ;
15171518 }
15181519 Py_DECREF (package_name );
0 commit comments