Skip to content

Commit

Permalink
#1040 disk_partitions() / linux: fix unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed May 2, 2017
1 parent 3681cd7 commit 79e30c2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions psutil/_psutil_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ static PyObject *
psutil_disk_partitions(PyObject *self, PyObject *args) {
FILE *file = NULL;
struct mntent *entry;
PyObject *py_retlist = PyList_New(0);
PyObject *py_dev = NULL;
PyObject *py_mountp = NULL;
PyObject *py_tuple = NULL;
PyObject *py_retlist = PyList_New(0);

if (py_retlist == NULL)
return NULL;
Expand All @@ -215,15 +217,23 @@ psutil_disk_partitions(PyObject *self, PyObject *args) {
PyErr_Format(PyExc_RuntimeError, "getmntent() syscall failed");
goto error;
}
py_tuple = Py_BuildValue("(ssss)",
entry->mnt_fsname, // device
entry->mnt_dir, // mount point
py_dev = PyUnicode_DecodeFSDefault(entry->mnt_fsname);
if (! py_dev)
goto error;
py_mountp = PyUnicode_DecodeFSDefault(entry->mnt_dir);
if (! py_mountp)
goto error;
py_tuple = Py_BuildValue("(OOss)",
py_dev, // device
py_mountp, // mount point
entry->mnt_type, // fs type
entry->mnt_opts); // options
if (! py_tuple)
goto error;
if (PyList_Append(py_retlist, py_tuple))
goto error;
Py_DECREF(py_dev);
Py_DECREF(py_mountp);
Py_DECREF(py_tuple);
}
endmntent(file);
Expand All @@ -232,6 +242,8 @@ psutil_disk_partitions(PyObject *self, PyObject *args) {
error:
if (file != NULL)
endmntent(file);
Py_XDECREF(py_dev);
Py_XDECREF(py_mountp);
Py_XDECREF(py_tuple);
Py_DECREF(py_retlist);
return NULL;
Expand Down

0 comments on commit 79e30c2

Please sign in to comment.