summaryrefslogtreecommitdiffstats
path: root/python-ethtool/ethtool.c
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2011-04-11 14:30:36 +0200
committerDavid Sommerseth <davids@redhat.com>2011-04-11 14:30:36 +0200
commitabc7f912f66d41dd734a10900429d4cad9377da5 (patch)
tree91e26638c7d7a84fe750d037ca0231a34463ff30 /python-ethtool/ethtool.c
parent710766dc72260149bd78fd6168fbaf6838fc3d4f (diff)
downloadpython-ethtool-abc7f912f66d41dd734a10900429d4cad9377da5.tar.gz
python-ethtool-abc7f912f66d41dd734a10900429d4cad9377da5.tar.xz
python-ethtool-abc7f912f66d41dd734a10900429d4cad9377da5.zip
Fixed several memory leaks
Several places python-ethtool leaked memory, mostly due to missing Py_DECREF() calls on objects being put in to python lists (via PyList_Append() calls). This revealed an issue in addition where the IPv6 addresses pointers in some cases could freed more times. This is fixed as well. Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'python-ethtool/ethtool.c')
-rw-r--r--python-ethtool/ethtool.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/python-ethtool/ethtool.c b/python-ethtool/ethtool.c
index a29f052..60e407c 100644
--- a/python-ethtool/ethtool.c
+++ b/python-ethtool/ethtool.c
@@ -93,8 +93,11 @@ static PyObject *get_active_devices(PyObject *self __unused, PyObject *args __un
ifr = ifc.ifc_req;
for (n = 0; n < ifc.ifc_len; n += sizeof(struct ifreq)) {
if (!(ioctl(skfd, SIOCGIFFLAGS, ifr) < 0))
- if (ifr->ifr_flags & IFF_UP)
- PyList_Append(list, PyString_FromString(ifr->ifr_name));
+ if (ifr->ifr_flags & IFF_UP) {
+ PyObject *str = PyString_FromString(ifr->ifr_name);
+ PyList_Append(list, str);
+ Py_DECREF(str);
+ }
ifr++;
}
@@ -118,6 +121,7 @@ static PyObject *get_devices(PyObject *self __unused, PyObject *args __unused)
/* skip over first two lines */
ret = fgets(buffer, 256, fd); ret = fgets(buffer, 256, fd);
while (!feof(fd)) {
+ PyObject *str;
char *name = buffer;
char *end = buffer;
@@ -129,7 +133,10 @@ static PyObject *get_devices(PyObject *self __unused, PyObject *args __unused)
*end = 0; /* terminate where colon was */
while (*name == ' ')
name++; /* skip over leading whitespace if any */
- PyList_Append(list, PyString_FromString(name));
+
+ str = PyString_FromString(name);
+ PyList_Append(list, str);
+ Py_DECREF(str);
}
fclose(fd);
return list;
@@ -320,7 +327,9 @@ static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
PyObject *dev = PyObject_CallObject((PyObject *)&ethtool_etherinfoType, args);
if( dev ) {
PyList_Append(devlist, dev);
+ Py_DECREF(dev);
}
+ Py_DECREF(args);
}
}
if( fetch_devs_len > 0 ) {