]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-144986: Fix memory leak in atexit.register() (GH-144987) (#145020)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 16 Mar 2026 08:26:05 +0000 (09:26 +0100)
committerGitHub <noreply@github.com>
Mon, 16 Mar 2026 08:26:05 +0000 (13:56 +0530)
gh-144986: Fix memory leak in atexit.register() (GH-144987)
(cherry picked from commit 50c14719fbd47f500dd1a468998201d22475126d)

Co-authored-by: Shamil <ashm.tech@proton.me>
Misc/NEWS.d/next/Library/2026-02-19-00-00-00.gh-issue-144986.atexit-leak.rst [new file with mode: 0644]
Modules/atexitmodule.c

diff --git a/Misc/NEWS.d/next/Library/2026-02-19-00-00-00.gh-issue-144986.atexit-leak.rst b/Misc/NEWS.d/next/Library/2026-02-19-00-00-00.gh-issue-144986.atexit-leak.rst
new file mode 100644 (file)
index 0000000..841c375
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a memory leak in :func:`atexit.register`.
+Patch by Shamil Abdulaev.
index c3aad96bba6eb287ca93bd3aa000924e9d0b8c77..d2f739cecfbb08d68b22de151464b08d8c89b6cc 100644 (file)
@@ -184,6 +184,9 @@ atexit_register(PyObject *module, PyObject *args, PyObject *kwargs)
         return NULL;
     }
     PyObject *func_args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
+    if (func_args == NULL) {
+        return NULL;
+    }
     PyObject *func_kwargs = kwargs;
 
     if (func_kwargs == NULL)
@@ -191,6 +194,7 @@ atexit_register(PyObject *module, PyObject *args, PyObject *kwargs)
         func_kwargs = Py_None;
     }
     PyObject *callback = PyTuple_Pack(3, func, func_args, func_kwargs);
+    Py_DECREF(func_args);
     if (callback == NULL)
     {
         return NULL;