Skip to content

Commit

Permalink
#1040 / FreeBSD: fix net_connections('unix') which may raise decoding…
Browse files Browse the repository at this point in the history
… error on py3
  • Loading branch information
giampaolo committed Apr 30, 2017
1 parent 8646be5 commit cdc9b4f
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions psutil/arch/bsd/freebsd_socks.c
Expand Up @@ -358,8 +358,7 @@ int psutil_gather_unix(int proto, PyObject *py_retlist) {
char path[PATH_MAX];

PyObject *py_tuple = NULL;
PyObject *py_laddr = NULL;
PyObject *py_raddr = NULL;
PyObject *py_lpath = NULL;

switch (proto) {
case SOCK_STREAM:
Expand Down Expand Up @@ -418,13 +417,23 @@ int psutil_gather_unix(int proto, PyObject *py_retlist) {
snprintf(path, sizeof(path), "%.*s",
(int)(sun->sun_len - (sizeof(*sun) - sizeof(sun->sun_path))),
sun->sun_path);
py_lpath = psutil_PyUnicode_DecodeFSDefault(path);
if (! py_lpath)
goto error;

py_tuple = Py_BuildValue("(iiisOii)", -1, AF_UNIX, proto, path,
Py_None, PSUTIL_CONN_NONE, pid);
py_tuple = Py_BuildValue("(iiiOOii)",
-1,
AF_UNIX,
proto,
py_lpath,
Py_None,
PSUTIL_CONN_NONE,
pid);
if (!py_tuple)
goto error;
if (PyList_Append(py_retlist, py_tuple))
goto error;
Py_DECREF(py_lpath);
Py_DECREF(py_tuple);
Py_INCREF(Py_None);
}
Expand All @@ -434,8 +443,7 @@ int psutil_gather_unix(int proto, PyObject *py_retlist) {

error:
Py_XDECREF(py_tuple);
Py_XDECREF(py_laddr);
Py_XDECREF(py_raddr);
Py_XDECREF(py_lpath);
free(buf);
return 0;
}
Expand Down

0 comments on commit cdc9b4f

Please sign in to comment.