diff --git a/HISTORY.rst b/HISTORY.rst index dc49d65fa..35185d62e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -27,6 +27,8 @@ skipping a file which gets deleted while open files are retrieved. - 1029_: [OSX, FreeBSD] Process.connections('unix') on Python 3 doesn't properly handle unicode paths and may raise UnicodeDecodeError. +- 1033_: [OSX, FreeBSD] memory leak for net_connections() and + Process.connections() when retrieving UNIX sockets (kind='unix'). *2017-04-10* diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index 90391ddc0..559ffab9f 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -1384,6 +1384,8 @@ psutil_proc_connections(PyObject *self, PyObject *args) { if (PyList_Append(py_retlist, py_tuple)) goto error; Py_DECREF(py_tuple); + Py_DECREF(py_laddr); + Py_DECREF(py_raddr); } } } diff --git a/psutil/arch/bsd/freebsd_socks.c b/psutil/arch/bsd/freebsd_socks.c index b30fa8f81..187a93de0 100644 --- a/psutil/arch/bsd/freebsd_socks.c +++ b/psutil/arch/bsd/freebsd_socks.c @@ -618,6 +618,7 @@ psutil_proc_connections(PyObject *self, PyObject *args) { if (PyList_Append(py_retlist, py_tuple)) goto error; Py_DECREF(py_tuple); + Py_DECREF(py_laddr); Py_INCREF(Py_None); } } diff --git a/psutil/tests/test_connections.py b/psutil/tests/test_connections.py index 28670f25c..e1e9fca8a 100644 --- a/psutil/tests/test_connections.py +++ b/psutil/tests/test_connections.py @@ -53,7 +53,9 @@ def compare_proc_sys_cons(self, pid, proc_cons): except psutil.AccessDenied: # On OSX, system-wide connections are retrieved by iterating # over all processes - if not OSX: + if OSX: + return + else: raise # exclude PIDs from syscons syscons = [c[:-1] for c in syscons if c.pid == pid] diff --git a/psutil/tests/test_memory_leaks.py b/psutil/tests/test_memory_leaks.py index 402e7b8bb..2bf7882ce 100755 --- a/psutil/tests/test_memory_leaks.py +++ b/psutil/tests/test_memory_leaks.py @@ -367,7 +367,7 @@ def create_socket(family, type): return sock # Open as many socket types as possible so that we excercise - # as much C code sections as possible. + # as many C code sections as possible. socks = [] socks.append(create_socket(socket.AF_INET, socket.SOCK_STREAM)) socks.append(create_socket(socket.AF_INET, socket.SOCK_DGRAM))