Issue #16305: Merge fix from 3.3.
diff --git a/Misc/NEWS b/Misc/NEWS
index c2814a0..db55df1 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -62,6 +62,9 @@
 Library
 -------
 
+- Issue #16305: Fix a segmentation fault occurring when interrupting
+  math.factorial.
+
 - Issue #16116: Fix include and library paths to be correct when building C
   extensions in venvs.
 
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index d693da1..3fa52d0 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -1381,14 +1381,13 @@
         Py_DECREF(outer);
         outer = tmp;
     }
-
-    goto done;
+    Py_DECREF(inner);
+    return outer;
 
   error:
     Py_DECREF(outer);
-  done:
     Py_DECREF(inner);
-    return outer;
+    return NULL;
 }
 
 /* Lookup table for small factorial values */