diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-02 05:43:54 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-02 05:43:54 +0200 |
commit | f23d7b2a8cb2b91bebbad318d7bdb45357636e62 (patch) | |
tree | e7be708af712d195426dde79dcf2363d4c39d44b /psutil/_psutil_sunos.c | |
parent | d1ddeb5b4ec34afa86f168243e25699234ac22b4 (diff) | |
download | psutil-f23d7b2a8cb2b91bebbad318d7bdb45357636e62.tar.gz |
#1040 / disk_partitions() / sunos: fix unicode
Diffstat (limited to 'psutil/_psutil_sunos.c')
-rw-r--r-- | psutil/_psutil_sunos.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c index ceb32cf5..aaca1ffb 100644 --- a/psutil/_psutil_sunos.c +++ b/psutil/_psutil_sunos.c @@ -518,8 +518,10 @@ static PyObject * psutil_disk_partitions(PyObject *self, PyObject *args) { FILE *file; struct mnttab mt; - 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; @@ -531,23 +533,32 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { } while (getmntent(file, &mt) == 0) { + py_dev = PyUnicode_DecodeFSDefault(mt.mnt_special); + if (! py_dev) + goto error; + py_mountp = PyUnicode_DecodeFSDefault(mt.mnt_mountp); + if (! py_mountp) + goto error; py_tuple = Py_BuildValue( - "(ssss)", - mt.mnt_special, // device - mt.mnt_mountp, // mount point + "(OOss)", + py_dev, // device + py_mountp, // mount point mt.mnt_fstype, // fs type mt.mnt_mntopts); // options if (py_tuple == NULL) goto error; if (PyList_Append(py_retlist, py_tuple)) goto error; + Py_DECREF(py_dev); + Py_DECREF(py_mountp); Py_DECREF(py_tuple); - } fclose(file); return py_retlist; error: + Py_XDECREF(py_dev); + Py_XDECREF(py_mountp); Py_XDECREF(py_tuple); Py_DECREF(py_retlist); if (file != NULL) |