if FileIO.__init__ fails, close fd
diff --git a/Misc/NEWS b/Misc/NEWS
index cadafd0..21dcacf 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
 Core and Builtins
 -----------------
 
+- If FileIO.__init__ fails, close the file descriptor.
+
 - Issue #10221: dict.pop(k) now has a key error message that includes the
   missing key (same message d[k] returns for missing keys).
 
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 37ff25c..09ea80f 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -410,6 +410,8 @@
 
  error:
     ret = -1;
+    if (self->fd >= 0)
+        internal_close(self);
 
  done:
     Py_CLEAR(stringobj);