From a05f17ca5737d03b127dd599363f009d5c6c8d48 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Mon, 16 Dec 2013 12:17:03 +0100 Subject: Make the internal MAC address a Python string object Signed-off-by: David Sommerseth --- python-ethtool/etherinfo.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'python-ethtool/etherinfo.c') 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 @@ -41,20 +41,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 * @@ -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); } -- cgit