commit: 038ad1029ea574b106906380e47479db1041bee2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Wed Feb 14 05:55:31 2024 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Wed Feb 14 06:04:22 2024 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=038ad102
BuildLogger: Fix portage.locks._open_fds memory leak The _file_close_wrapper __getattribute__ method needs to be overridden to expose its close method, otherwise the underlying file's close method is called and the closed file object remains as a memory leak in the global portage.locks._open_fds dict. For reference, see similar classes like portage.util.atomic_ofstream which overrides methods in the same way. Bug: https://bugs.gentoo.org/919072 Fixes: df212738bbb2 ("BuildLogger: Close self._stdin after fork") Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> lib/portage/util/_async/BuildLogger.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/portage/util/_async/BuildLogger.py b/lib/portage/util/_async/BuildLogger.py index 9f8a21ab2b..0cfc90a942 100644 --- a/lib/portage/util/_async/BuildLogger.py +++ b/lib/portage/util/_async/BuildLogger.py @@ -1,4 +1,4 @@ -# Copyright 2020-2023 Gentoo Authors +# Copyright 2020-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import functools @@ -31,6 +31,11 @@ class _file_close_wrapper(ObjectProxy): def _get_target(self): return object.__getattribute__(self, "_file") + def __getattribute__(self, attr): + if attr == "close": + return object.__getattribute__(self, attr) + return getattr(object.__getattribute__(self, "_file"), attr) + def close(self): file = object.__getattribute__(self, "_file") if not file.closed:
