Issue #28715: Added error checks for PyUnicode_AsUTF8().
diff --git a/Python/importdl.c b/Python/importdl.c
index 1aa585d..ea4f0e7 100644
--- a/Python/importdl.c
+++ b/Python/importdl.c
@@ -147,6 +147,10 @@
     /* Package context is needed for single-phase init */
     oldcontext = _Py_PackageContext;
     _Py_PackageContext = PyUnicode_AsUTF8(name_unicode);
+    if (_Py_PackageContext == NULL) {
+        _Py_PackageContext = oldcontext;
+        goto error;
+    }
     m = p0();
     _Py_PackageContext = oldcontext;