On 5/4/19 1:26 AM, Zhiqiang Liu wrote: > > diff --git a/ip/ipnetns.c b/ip/ipnetns.c > index 430d884..d72be95 100644 > --- a/ip/ipnetns.c > +++ b/ip/ipnetns.c > @@ -107,7 +107,7 @@ int get_netnsid_from_name(const char *name) > struct nlmsghdr *answer; > struct rtattr *tb[NETNSA_MAX + 1]; > struct rtgenmsg *rthdr; > - int len, fd; > + int len, fd, ret = -1; > > netns_nsid_socket_init(); > > @@ -134,8 +134,9 @@ int get_netnsid_from_name(const char *name) > parse_rtattr(tb, NETNSA_MAX, NETNS_RTA(rthdr), len); > > if (tb[NETNSA_NSID]) { > + ret = rta_getattr_u32(tb[NETNSA_NSID]); > free(answer); > - return rta_getattr_u32(tb[NETNSA_NSID]); > + return ret;
set ret here, drop the free, let it proceed down to the existing free and return but now using ret. That way there is 1 exit path and handles the cleanup. > } > > err_out: >