Skip to content

Commit c52ed2c

Browse files
author
David Sommerseth
committed
Python reference counter was not properly set for etherinfo_ipv6addr objects
This caused a double free situation, when Python tried to free the object if the etherinfo::get_ipv6_addresses() method was called several times. In addition the ethtool::get_interfaces_info() would also free the structures uses by etherinfo_ipv6addr objects. Signed-off-by: David Sommerseth <davids@redhat.com>
1 parent fca9911 commit c52ed2c

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

python-ethtool/etherinfo.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ void free_ipv6addresses(struct ipv6address *ptr) {
6666
while( ipv6ptr ) {
6767
struct ipv6address *tmp = ipv6ptr->next;
6868

69-
free(ipv6ptr->address);
69+
if( ipv6ptr->address ) {
70+
free(ipv6ptr->address);
71+
}
7072
free(ipv6ptr);
7173
ipv6ptr = tmp;
7274
}
@@ -313,10 +315,6 @@ int get_etherinfo(struct etherinfo *ethinf, struct nl_handle *nlc, nlQuery query
313315
break;
314316

315317
case NLQRY_ADDR:
316-
/* Remove old IPv6 information we might have */
317-
free_ipv6addresses(ethinf->ipv6_addresses);
318-
ethinf->ipv6_addresses = NULL;
319-
320318
/* Extract IP address information */
321319
addr_cache = rtnl_addr_alloc_cache(nlc);
322320
addr = rtnl_addr_alloc();

python-ethtool/etherinfo_obj.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ PyObject * _ethtool_etherinfo_get_ipv6_addresses(etherinfo_py *self, PyObject *n
234234
if( ipv6_pyobj ) {
235235
PyTuple_SetItem(ret, i++, ipv6_pyobj);
236236
_PyTuple_Resize(&ret, i+1);
237+
Py_INCREF(ipv6_pyobj);
237238
}
238239
ipv6 = next;
239240
}

0 commit comments

Comments
 (0)