[PATCH 1/4] veth: alloc link struct for peer when parsing netlink message
Thomas Graf
tgraf at suug.ch
Thu Mar 27 05:25:14 EDT 2014
On 03/27/14 at 09:13am, Thomas Graf wrote:
> On 03/23/14 at 12:02pm, Cong Wang wrote:
> > Signed-off-by: Cong Wang <xiyou.wangcong at gmail.com>
> > ---
> > lib/route/link/veth.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/route/link/veth.c b/lib/route/link/veth.c
> > index 4ce1f10..0cac428 100644
> > --- a/lib/route/link/veth.c
> > +++ b/lib/route/link/veth.c
> > @@ -42,7 +42,6 @@ static int veth_parse(struct rtnl_link *link, struct nlattr *data,
> > {
> > struct nlattr *tb[VETH_INFO_MAX+1];
> > struct nlattr *peer_tb[IFLA_MAX + 1];
> > - struct rtnl_link *peer = link->l_info;
> > int err;
> >
> > NL_DBG(3, "Parsing veth link info");
> > @@ -51,9 +50,12 @@ static int veth_parse(struct rtnl_link *link, struct nlattr *data,
> > goto errout;
> >
> > if (tb[VETH_INFO_PEER]) {
> > + struct rtnl_link *peer = rtnl_link_alloc();
Why don't you just use io_alloc()? That way the peer link is always
around and you never need to check whether you have created it or not.
> > struct nlattr *nla_peer;
> > struct ifinfomsg *ifi;
> >
> > + if (!peer)
> > + return -NLE_NOMEM;
> > nla_peer = tb[VETH_INFO_PEER];
> > ifi = nla_data(nla_peer);
> >
> > @@ -72,6 +74,7 @@ static int veth_parse(struct rtnl_link *link, struct nlattr *data,
> > err = rtnl_link_info_parse(peer, peer_tb);
> > if (err < 0)
> > goto errout;
>
> I think peer is leaked in the error cases above.
>
> > + link->l_info = peer;
> > }
More information about the libnl
mailing list