[PATCH] veth: grab a reference for rtnl_link_veth_get_peer()

Cong Wang xiyou.wangcong at gmail.com
Tue Apr 15 13:42:46 PDT 2014


On Tue, Apr 15, 2014 at 4:01 AM, Thomas Haller <thaller at redhat.com> wrote:
> On Mon, 2014-04-14 at 18:39 -0700, Cong Wang wrote:
>> Signed-off-by: Cong Wang <xiyou.wangcong at gmail.com>
>> ---
>>  lib/route/link/veth.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/lib/route/link/veth.c b/lib/route/link/veth.c
>> index 19c84f8..3b6a89c 100644
>> --- a/lib/route/link/veth.c
>> +++ b/lib/route/link/veth.c
>> @@ -232,6 +232,7 @@ struct rtnl_link *rtnl_link_veth_alloc(void)
>>  struct rtnl_link *rtnl_link_veth_get_peer(struct rtnl_link *link)
>>  {
>>       IS_VETH_LINK_ASSERT(link);
>> +     nl_object_get(OBJ_CAST(link->l_info));
>
> rtnl_link_get(link->l_info); ?


I wish I could use it but:

struct rtnl_link *rtnl_link_get(struct nl_cache *cache, int ifindex)

See? :-)

>
>
>>       return link->l_info;
>>  }
>>
>
>
> I think, with this change rtnl_link_veth_add() and
> tests/test-create-veth.c now leaks a reference.
>

Good catch.

>
> This is a behavioral change since libnl3.2.24, but I think it is the
> right thing to do also because it's quite new and probably not used much
> yet(?).
>
> But could you add a "capability" to indicate that rtnl_link_veth_alloc()
> now gets an additional reference? Something like the attached patch (but
> maybe with a better name :) ). So in principle callers could handle it
> properly and workaround it.
>

Right, I think I should integrate your workaround into my patch, if you
don't mind...

Thanks!



More information about the libnl mailing list