summaryrefslogtreecommitdiffstats
path: root/python-ethtool/etherinfo.c
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2013-12-16 12:17:03 +0100
committerDavid Sommerseth <davids@redhat.com>2013-12-16 12:23:43 +0100
commita05f17ca5737d03b127dd599363f009d5c6c8d48 (patch)
treecb5213c2fd9aea198bf8b0be8f414b54cdfc99e9 /python-ethtool/etherinfo.c
parent3236cbdb03ed84271aeacc932760752a733204d4 (diff)
downloadpython-ethtool-a05f17ca5737d03b127dd599363f009d5c6c8d48.tar.gz
python-ethtool-a05f17ca5737d03b127dd599363f009d5c6c8d48.tar.xz
python-ethtool-a05f17ca5737d03b127dd599363f009d5c6c8d48.zip
Make the internal MAC address a Python string object
Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'python-ethtool/etherinfo.c')
-rw-r--r--python-ethtool/etherinfo.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/python-ethtool/etherinfo.c b/python-ethtool/etherinfo.c
index 6f7778c..37e86e3 100644
--- a/python-ethtool/etherinfo.c
+++ b/python-ethtool/etherinfo.c
@@ -42,20 +42,6 @@
*/
/**
- * Simple macro which makes sure the destination string is freed if used earlier.
- *
- * @param dst Destination pointer
- * @param src Source pointer
- *
- */
-#define SET_STR_VALUE(dst, src) { \
- if( dst ) { \
- free(dst); \
- }; \
- dst = strdup(src); \
- }
-
-/**
* Frees the memory used by struct etherinfo
*
* @param ptr Pointer to a struct etherninfo element
@@ -68,9 +54,7 @@ void free_etherinfo(struct etherinfo *ptr)
free(ptr->device);
- if( ptr->hwaddress ) {
- free(ptr->hwaddress);
- }
+ Py_XDECREF(ptr->hwaddress);
Py_XDECREF(ptr->ipv4_addresses);
Py_XDECREF(ptr->ipv6_addresses);
@@ -97,7 +81,10 @@ static void callback_nl_link(struct nl_object *obj, void *arg)
memset(&hwaddr, 0, 130);
nl_addr2str(rtnl_link_get_addr(link), hwaddr, sizeof(hwaddr));
- SET_STR_VALUE(ethi->hwaddress, hwaddr);
+ if( ethi->hwaddress ) {
+ Py_XDECREF(ethi->hwaddress);
+ }
+ ethi->hwaddress = PyString_FromFormat("%s", hwaddr);
}