Skip to content

Commit

Permalink
#250: fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Feb 12, 2015
1 parent 9ae9b8c commit d03de6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 7 additions & 4 deletions psutil/_psutil_sunos.c
Original file line number Diff line number Diff line change
Expand Up @@ -1173,17 +1173,15 @@ psutil_net_if_stats(PyObject* self, PyObject* args)
PyObject *py_retdict = PyDict_New();
PyObject *py_ifc_info = NULL;
PyObject *py_is_up = NULL;
PyObject *py_ret = NULL;

if (py_retdict == NULL)
return NULL;
kc = kstat_open();
if (kc == NULL)
return PyErr_SetFromErrno(PyExc_OSError);

goto error;
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == -1)
return PyErr_SetFromErrno(PyExc_OSError);
goto error;

for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
if (strcmp(ksp->ks_class, "net") == 0) {
Expand Down Expand Up @@ -1248,12 +1246,17 @@ psutil_net_if_stats(PyObject* self, PyObject* args)
}

close(sock);
kstat_close(kc);
return py_retdict;

error:
Py_XDECREF(py_is_up);
Py_XDECREF(py_ifc_info);
Py_DECREF(py_retdict);
if (sock != 0)
close(sock);
if (kc != NULL)
kstat_close(kc);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
Expand Down
6 changes: 0 additions & 6 deletions test/_sunos.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ def test_swap_memory(self):
self.assertEqual(psutil_swap.used, used)
self.assertEqual(psutil_swap.free, free)

def test_nic_names(self):
# Internally the C implementation uses almost the same
# routine so we want to make sure NIC names are the same.
self.assertEqual(sorted(psutil.net_io_counters(pernic=True).keys()),
sorted(psutil.net_if_stats().keys()))


def test_main():
test_suite = unittest.TestSuite()
Expand Down

0 comments on commit d03de6b

Please sign in to comment.