Skip to content

Commit

Permalink
#1040 / unicode / freebsd: fix decode handling for memory_maps() and …
Browse files Browse the repository at this point in the history
…open_files()
  • Loading branch information
giampaolo committed May 1, 2017
1 parent 21cb4a5 commit 3685cfd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 6 additions & 1 deletion psutil/_psutil_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ psutil_proc_open_files(PyObject *self, PyObject *args) {
struct kinfo_file *kif;
kinfo_proc kipp;
PyObject *py_tuple = NULL;
PyObject *py_path = NULL;
PyObject *py_retlist = PyList_New(0);

if (py_retlist == NULL)
Expand Down Expand Up @@ -498,12 +499,16 @@ psutil_proc_open_files(PyObject *self, PyObject *args) {
// XXX - it appears path is not exposed in the kinfo_file struct.
path = "";
#endif
py_path = psutil_PyUnicode_DecodeFSDefault(path);
if (! py_path)
goto error;
if (regular == 1) {
py_tuple = Py_BuildValue("(si)", path, fd);
py_tuple = Py_BuildValue("(Oi)", py_path, fd);
if (py_tuple == NULL)
goto error;
if (PyList_Append(py_retlist, py_tuple))
goto error;
Py_DECREF(py_path);
Py_DECREF(py_tuple);
}
}
Expand Down
12 changes: 9 additions & 3 deletions psutil/arch/bsd/freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,12 +746,13 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
int i, cnt;
char addr[1000];
char perms[4];
const char *path;
char *path;
struct kinfo_proc kp;
struct kinfo_vmentry *freep = NULL;
struct kinfo_vmentry *kve;
ptrwidth = 2 * sizeof(void *);
PyObject *py_tuple = NULL;
PyObject *py_path = NULL;
PyObject *py_retlist = PyList_New(0);

if (py_retlist == NULL)
Expand Down Expand Up @@ -820,10 +821,13 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
path = kve->kve_path;
}

py_tuple = Py_BuildValue("sssiiii",
py_path = psutil_PyUnicode_DecodeFSDefault(path);
if (! py_path)
goto error;
py_tuple = Py_BuildValue("ssOiiii",
addr, // "start-end" address
perms, // "rwx" permissions
path, // path
py_path, // path
kve->kve_resident, // rss
kve->kve_private_resident, // private
kve->kve_ref_count, // ref count
Expand All @@ -832,13 +836,15 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
goto error;
if (PyList_Append(py_retlist, py_tuple))
goto error;
Py_DECREF(py_path);
Py_DECREF(py_tuple);
}
free(freep);
return py_retlist;

error:
Py_XDECREF(py_tuple);
Py_XDECREF(py_path);
Py_DECREF(py_retlist);
if (freep != NULL)
free(freep);
Expand Down

0 comments on commit 3685cfd

Please sign in to comment.