Skip to content

Commit 92cc31a

Browse files
committed
nh: merge branch 'cpaasch-oai:t/nh_fixes'
#440
2 parents 9a0de52 + a2db153 commit 92cc31a

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/route/nh.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ static void rtnl_nh_grp_put(nl_nh_group_t *nhg)
9797
if (nhg->ce_refcnt > 0)
9898
return;
9999

100+
free(nhg->entries);
100101
free(nhg);
101102
}
102103

@@ -204,12 +205,28 @@ static void nexthop_keygen(struct nl_object *obj, uint32_t *hashkey,
204205

205206
int rtnl_nh_set_gateway(struct rtnl_nh *nexthop, struct nl_addr *addr)
206207
{
207-
if (nexthop->ce_mask & NH_ATTR_GATEWAY) {
208-
nl_addr_put(nexthop->nh_gateway);
208+
struct nl_addr *old = NULL;
209+
210+
if (!nexthop)
211+
return -NLE_INVAL;
212+
213+
/* preserve old pointer to release after successful update */
214+
old = nexthop->nh_gateway;
215+
216+
if (addr) {
217+
struct nl_addr *cloned = nl_addr_clone(addr);
218+
if (!cloned)
219+
return -NLE_NOMEM;
220+
221+
nexthop->nh_gateway = cloned;
222+
nexthop->ce_mask |= NH_ATTR_GATEWAY;
223+
} else {
224+
nexthop->nh_gateway = NULL;
225+
nexthop->ce_mask &= ~NH_ATTR_GATEWAY;
209226
}
210227

211-
nexthop->nh_gateway = nl_addr_clone(addr);
212-
nexthop->ce_mask |= NH_ATTR_GATEWAY;
228+
if (old)
229+
nl_addr_put(old);
213230

214231
return 0;
215232
}

0 commit comments

Comments
 (0)