From 6a9ca74c6fa5d88481648bb7be4355d756d23222 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Fri, 12 Jun 2015 23:22:21 +0200 Subject: (freebsd) fix memleak + add test --- psutil/_psbsd.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'psutil/_psbsd.py') diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index 3ce5fd1c..db54a02e 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -143,7 +143,11 @@ def cpu_count_physical(): if index != -1: s = s[:index + 9] root = ET.fromstring(s) - ret = len(root.findall('group/children/group/cpu')) or None + try: + ret = len(root.findall('group/children/group/cpu')) or None + finally: + # needed otherwise it will memleak + root.clear() if not ret: # If logical CPUs are 1 it's obvious we'll have only 1 # physical CPU. -- cgit v1.2.1