summaryrefslogtreecommitdiffstats
path: root/python-ethtool/etherinfo_obj.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/etherinfo_obj.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/etherinfo_obj.c')
-rw-r--r--python-ethtool/etherinfo_obj.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/python-ethtool/etherinfo_obj.c b/python-ethtool/etherinfo_obj.c
index aefb940..e1e03fe 100644
--- a/python-ethtool/etherinfo_obj.c
+++ b/python-ethtool/etherinfo_obj.c
@@ -167,6 +167,7 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
if( self->data->ethinfo->hwaddress ) {
PyObject *tmp = PyString_FromFormat("\tMAC address: %s\n", self->data->ethinfo->hwaddress);
PyString_Concat(&ret, tmp);
+ Py_DECREF(tmp);
}
if( self->data->ethinfo->ipv4_address ) {
@@ -174,19 +175,21 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
self->data->ethinfo->ipv4_address,
self->data->ethinfo->ipv4_netmask);
if( self->data->ethinfo->ipv4_broadcast ) {
- PyObject *tmp2 = PyString_FromFormat(" Broadcast: %s",
+ PyObject *tmp2 = PyString_FromFormat(" Broadcast: %s",
self->data->ethinfo->ipv4_broadcast);
PyString_Concat(&tmp, tmp2);
+ Py_DECREF(tmp2);
}
PyString_Concat(&tmp, PyString_FromString("\n"));
PyString_Concat(&ret, tmp);
+ Py_DECREF(tmp);
}
if( self->data->ethinfo->ipv6_addresses ) {
struct ipv6address *ipv6 = self->data->ethinfo->ipv6_addresses;
PyObject *tmp = PyString_FromFormat("\tIPv6 addresses:\n");
PyString_Concat(&ret, tmp);
-
+ Py_DECREF(tmp);
for( ; ipv6; ipv6 = ipv6->next) {
char scope[66];
@@ -194,6 +197,7 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
PyObject *addr = PyString_FromFormat("\t [%s] %s/%i\n",
scope, ipv6->address, ipv6->netmask);
PyString_Concat(&ret, addr);
+ Py_DECREF(addr);
}
}
return ret;
@@ -249,10 +253,10 @@ PyObject * _ethtool_etherinfo_get_ipv6_addresses(etherinfo_py *self, PyObject *n
}
PyTuple_SetItem(args, 0, ipv6_pydata);
ipv6_pyobj = PyObject_CallObject((PyObject *)&ethtool_etherinfoIPv6Type, args);
+ Py_DECREF(args);
if( ipv6_pyobj ) {
PyTuple_SetItem(ret, i++, ipv6_pyobj);
_PyTuple_Resize(&ret, i+1);
- Py_INCREF(ipv6_pyobj);
} else {
PyErr_SetString(PyExc_RuntimeError,
"[INTERNAL] Failed to initialise the new "
@@ -262,6 +266,7 @@ PyObject * _ethtool_etherinfo_get_ipv6_addresses(etherinfo_py *self, PyObject *n
ipv6 = next;
}
_PyTuple_Resize(&ret, i);
+ self->data->ethinfo->ipv6_addresses = NULL;
return ret;
}