]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-139988: fix a leak when failing to create a Union type (#139990)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sun, 12 Oct 2025 10:51:44 +0000 (12:51 +0200)
committerGitHub <noreply@github.com>
Sun, 12 Oct 2025 10:51:44 +0000 (12:51 +0200)
Misc/NEWS.d/next/Core_and_Builtins/2025-10-12-11-00-06.gh-issue-139988.4wi51t.rst [new file with mode: 0644]
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 (file)
index 0000000..60fa3b1
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a memory leak when failing to create a :class:`~typing.Union` type.
+Patch by Bénédikt Tran.
index 2206ed80ef03fdfdf301d1b0ff177dc84a06004e..c4ece0fe09f01854bc5494568203179f4061347c 100644 (file)
@@ -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;
         }
     }