Change in vdsm[master]: vdsm: Fix memory leak in netlink/link.py

jtt77777 at yahoo.com jtt77777 at yahoo.com
Tue Mar 31 17:04:55 UTC 2015


John Taylor has uploaded a new change for review.

Change subject: vdsm: Fix memory leak in netlink/link.py
......................................................................

vdsm: Fix memory leak in netlink/link.py

The documentation for libnl says that calls to rtnl_link_get_by_name
increment the reference counter and should be released by a call to
rtnl_link_put().  That's not done in the
_rtnl_link_get_kernel_workaround(sock, name) function where it is used
and causes a memory leak.

Add a C function prototype for the libnl rtnl_link_put function, and
immediately call it with the link returned from
rtnl_link_get_by_name. This will decrement the reference counter so
the eventual call to _nl_cache_free(cache) for the used cache will be
able to free all of its link objects.

Change-Id: I883ce5f5c1ad0c0813d5d659de71761126a8fc80
Bug-Url: https://bugzilla.redhat.com/1158108
Signed-off-by: John Taylor <jtt77777 at yahoo.com>
---
M lib/vdsm/netlink/link.py
1 file changed, 5 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/16/39416/1

diff --git a/lib/vdsm/netlink/link.py b/lib/vdsm/netlink/link.py
index 0aafdb6..0f34b39 100644
--- a/lib/vdsm/netlink/link.py
+++ b/lib/vdsm/netlink/link.py
@@ -24,7 +24,7 @@
 
 from . import _cache_manager, _nl_cache_get_first, _nl_cache_get_next
 from . import _char_proto, _int_char_proto, _int_proto, _void_proto
-from . import LIBNL_ROUTE, _nl_geterror, _pool
+from . import LIBNL_ROUTE, _nl_geterror, _pool, _none_proto
 from . import _addr_to_str, CHARBUFFSIZE
 
 
@@ -146,7 +146,9 @@
 # workaround for el6
 def _rtnl_link_get_kernel_workaround(sock, name):
     with _nl_link_cache(sock) as cache:
-        return _rtnl_link_get_by_name(cache, name)
+        link = _rtnl_link_get_by_name(cache, name)
+        _rtnl_link_put(link)
+        return link
 
 
 def _get_link(name=None, index=0, sock=None):
@@ -195,3 +197,4 @@
     'rtnl_link_i2name', LIBNL_ROUTE))
 _rtnl_link_operstate2str = _int_char_proto(('rtnl_link_operstate2str',
                                             LIBNL_ROUTE))
+_rtnl_link_put  = _none_proto(('rtnl_link_put', LIBNL_ROUTE))


-- 
To view, visit https://gerrit.ovirt.org/39416
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I883ce5f5c1ad0c0813d5d659de71761126a8fc80
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: John Taylor <jtt77777 at yahoo.com>


More information about the vdsm-patches mailing list