https://github.com/python/cpython/commit/3b9694a8e6db8c401b8f02e021c1416023f8f90a
commit: 3b9694a8e6db8c401b8f02e021c1416023f8f90a
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: picnixz <[email protected]>
date: 2025-10-12T11:16:43Z
summary:

[3.14] gh-139988: fix a leak when failing to create a Union type (GH-139990) 
(#139993)

gh-139988: fix a leak when failing to create a Union type (GH-139990)
(cherry picked from commit 6710156bd27dd48493d15f515506a0ead5d0328f)

Co-authored-by: Bénédikt Tran <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2025-10-12-11-00-06.gh-issue-139988.4wi51t.rst
M Objects/unionobject.c

diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2025-10-12-11-00-06.gh-issue-139988.4wi51t.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-12-11-00-06.gh-issue-139988.4wi51t.rst
new file mode 100644
index 00000000000000..60fa3b1d339cb1
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-12-11-00-06.gh-issue-139988.4wi51t.rst
@@ -0,0 +1,2 @@
+Fix a memory leak when failing to create a :class:`~typing.Union` type.
+Patch by Bénédikt Tran.
diff --git a/Objects/unionobject.c b/Objects/unionobject.c
index 2206ed80ef03fd..c4ece0fe09f018 100644
--- a/Objects/unionobject.c
+++ b/Objects/unionobject.c
@@ -474,11 +474,13 @@ _Py_union_from_tuple(PyObject *args)
     }
     if (PyTuple_CheckExact(args)) {
         if (!unionbuilder_add_tuple(&ub, args)) {
+            unionbuilder_finalize(&ub);
             return NULL;
         }
     }
     else {
         if (!unionbuilder_add_single(&ub, args)) {
+            unionbuilder_finalize(&ub);
             return NULL;
         }
     }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to