New submission from Josh Rosenberg: Minor bug introduced while implementing the fix for #7830:
In the case where functools.partial is wrapping another functools.partial instance, both of them providing positional arguments, the value nargs is not freed when the tuple concatenation fails and the constructor raises an Exception/returns NULL. Only nargs has the problem (it's a slice of the args passed to the function); pargs is a borrowed reference so there is no leak there. Admittedly, the odds of failure is incredibly low, but best to fix it on principle. Code link: https://hg.python.org/cpython/file/5a2692911a43/Modules/_functoolsmodule.c#l77 The simplest fix is to add the explicit DECREF in the error path: pto->args = PySequence_Concat(pargs, nargs); if (pto->args == NULL) { pto->kw = NULL; Py_DECREF(nargs); // <-- New Py_DECREF(pto); return NULL; } All other code paths hit a DECREF later on, no other fixes required. I'd submit a proper patch, but I'm on a new machine and I've got a lot of work to get the repos set up again. ---------- components: Extension Modules messages: 258176 nosy: belopolsky, josh.r priority: normal severity: normal status: open title: Reference leak in functools.partial constructor in failure case versions: Python 3.5, Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26104> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com