]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-144986: Fix memory leak in atexit.register() (#144987)
authorShamil <ashm.tech@proton.me>
Thu, 19 Feb 2026 20:42:55 +0000 (23:42 +0300)
committerGitHub <noreply@github.com>
Thu, 19 Feb 2026 20:42:55 +0000 (20:42 +0000)
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 1c901d9124d9cac3e194d3f80414039990f75df6..3ddbbd59a1ef0c3146fe4d4e24ebe656ff40986f 100644 (file)
@@ -185,6 +185,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)
@@ -192,6 +195,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;