diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2015-06-12 23:22:21 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2015-06-12 23:22:21 +0200 |
commit | 6a9ca74c6fa5d88481648bb7be4355d756d23222 (patch) | |
tree | 93f1cbf818768bc7ef891ad2c2049ed84dec29b6 | |
parent | a302a9922b58fca5763ccb03c60a121f45da7bdf (diff) | |
download | psutil-6a9ca74c6fa5d88481648bb7be4355d756d23222.tar.gz |
(freebsd) fix memleak + add test
-rw-r--r-- | psutil/_psbsd.py | 6 | ||||
-rw-r--r-- | test/_bsd.py | 4 |
2 files changed, 9 insertions, 1 deletions
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. diff --git a/test/_bsd.py b/test/_bsd.py index 76f12442..e4a3225d 100644 --- a/test/_bsd.py +++ b/test/_bsd.py @@ -187,6 +187,10 @@ class BSDSpecificTestCase(unittest.TestCase): self.assertAlmostEqual(psutil.virtual_memory().buffers, syst, delta=TOLERANCE) + def test_cpu_count_logical(self): + syst = sysctl("hw.ncpu") + self.assertEqual(psutil.cpu_count(logical=True), syst) + # --- virtual_memory(); tests against muse @unittest.skipUnless(MUSE_AVAILABLE, "muse cmdline tool is not available") |