Skip to content

Commit

Permalink
#1033 / net|proc connections / FreeBSD / OSX / memory leak: Py_DECREF…
Browse files Browse the repository at this point in the history
… object when retrieving UNIX sockets
  • Loading branch information
giampaolo committed Apr 29, 2017
1 parent c268d3c commit a759a04
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
2 changes: 2 additions & 0 deletions psutil/_psutil_osx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions psutil/arch/bsd/freebsd_socks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 3 additions & 1 deletion psutil/tests/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_memory_leaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit a759a04

Please sign in to comment.