https://github.com/python/cpython/commit/a1f2fefc327b87dba37581377d756fdb14576b91
commit: a1f2fefc327b87dba37581377d756fdb14576b91
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-03-16T13:56:05+05:30
summary:

[3.14] gh-144986: Fix memory leak in atexit.register() (GH-144987) (#145020)

gh-144986: Fix memory leak in atexit.register() (GH-144987)
(cherry picked from commit 50c14719fbd47f500dd1a468998201d22475126d)

Co-authored-by: Shamil <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-02-19-00-00-00.gh-issue-144986.atexit-leak.rst
M 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
index 00000000000000..841c3758ec4df1
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Library/2026-02-19-00-00-00.gh-issue-144986.atexit-leak.rst
@@ -0,0 +1,2 @@
+Fix a memory leak in :func:`atexit.register`.
+Patch by Shamil Abdulaev.
diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c
index c3aad96bba6eb2..d2f739cecfbb08 100644
--- a/Modules/atexitmodule.c
+++ b/Modules/atexitmodule.c
@@ -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;

_______________________________________________
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