@@ -127,18 +127,16 @@ static int _set_device_index(PyEtherInfo *self)
127127 */
128128 if ( self -> index < 0 ) {
129129 if ( (errno = rtnl_link_alloc_cache (get_nlc (), AF_UNSPEC , & link_cache )) < 0 ) {
130- PyErr_SetString (PyExc_OSError , nl_geterror (errno ));
131- return 0 ;
132- }
133-
134- link = rtnl_link_get_by_name (link_cache , PyBytes_AsString (self -> device ));
135- if ( !link ) {
130+ PyErr_SetString (PyExc_OSError , nl_geterror (errno ));
131+ return 0 ;
132+ }
133+ link = rtnl_link_get_by_name (link_cache , PyStr_AsString (self -> device ));
134+ if ( !link ) {
136135 errno = ENODEV ;
137136 PyErr_SetFromErrno (PyExc_IOError );
138137 nl_cache_free (link_cache );
139- return 0 ;
140- }
141-
138+ return 0 ;
139+ }
142140 self -> index = rtnl_link_get_ifindex (link );
143141 if ( self -> index <= 0 ) {
144142 errno = ENODEV ;
@@ -147,6 +145,7 @@ static int _set_device_index(PyEtherInfo *self)
147145 nl_cache_free (link_cache );
148146 return 0 ;
149147 }
148+
150149 rtnl_link_put (link );
151150 nl_cache_free (link_cache );
152151 }
@@ -244,20 +243,21 @@ PyObject * get_etherinfo_address(PyEtherInfo *self, nlQuery query)
244243 }
245244
246245 /* Query the for requested info via NETLINK */
247-
248- /* Extract IP address information */
249- if ( (err = rtnl_addr_alloc_cache (get_nlc (), & addr_cache )) < 0 ) {
250- PyErr_SetString (PyExc_OSError , nl_geterror (err ));
251- nl_cache_free (addr_cache );
252- return NULL ;
253- }
254- addr = rtnl_addr_alloc ();
255- if ( !addr ) {
256- errno = ENOMEM ;
257- PyErr_SetFromErrno (PyExc_OSError );
258- return NULL ;
259- }
260- rtnl_addr_set_ifindex (addr , self -> index );
246+ /* Extract IP address information */
247+ if ( (err = rtnl_addr_alloc_cache (get_nlc (), & addr_cache )) < 0 ) {
248+ PyErr_SetString (PyExc_OSError , nl_geterror (err ));
249+ nl_cache_free (addr_cache );
250+ return NULL ;
251+ }
252+
253+ addr = rtnl_addr_alloc ();
254+
255+ if ( !addr ) {
256+ errno = ENOMEM ;
257+ PyErr_SetFromErrno (PyExc_OSError );
258+ return NULL ;
259+ }
260+ rtnl_addr_set_ifindex (addr , self -> index );
261261
262262 switch ( query ) {
263263 case NLQRY_ADDR4 :
0 commit comments