Skip to content

Commit

Permalink
zebra: Do not forget to free opaque data for route entry
Browse files Browse the repository at this point in the history
Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Aug 13, 2024
1 parent 423e807 commit 32b9c30
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion zebra/rt_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ int netlink_route_change_read_unicast_internal(struct nlmsghdr *h,
zlog_err(
"%s: %pFX multipath RTM_NEWROUTE has a invalid nexthop group from the kernel",
__func__, &p);
XFREE(MTYPE_RE, re);
zebra_rib_route_entry_free(re);
}
} else {
if (ctx) {
Expand Down
13 changes: 5 additions & 8 deletions zebra/zapi_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)
__func__, &api.prefix,
zebra_route_string(client->proto));

XFREE(MTYPE_RE, re);
zebra_rib_route_entry_free(re);
return;
}

Expand All @@ -2173,7 +2173,7 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)

nexthop_group_delete(&ng);
zebra_nhg_backup_free(&bnhg);
XFREE(MTYPE_RE, re);
zebra_rib_route_entry_free(re);
return;
}

Expand All @@ -2192,8 +2192,7 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)
__func__);
nexthop_group_delete(&ng);
zebra_nhg_backup_free(&bnhg);
XFREE(MTYPE_RE_OPAQUE, re->opaque);
XFREE(MTYPE_RE, re);
zebra_rib_route_entry_free(re);
return;
}
if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX))
Expand All @@ -2205,8 +2204,7 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)
__func__, api.safi);
nexthop_group_delete(&ng);
zebra_nhg_backup_free(&bnhg);
XFREE(MTYPE_RE_OPAQUE, re->opaque);
XFREE(MTYPE_RE, re);
zebra_rib_route_entry_free(re);
return;
}

Expand Down Expand Up @@ -2235,8 +2233,7 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)
*/
if (ret == -1) {
client->error_cnt++;
XFREE(MTYPE_RE_OPAQUE, re->opaque);
XFREE(MTYPE_RE, re);
zebra_rib_route_entry_free(re);
}

/* At this point, these allocations are not needed: 're' has been
Expand Down
10 changes: 4 additions & 6 deletions zebra/zebra_rib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2696,8 +2696,7 @@ static void early_route_memory_free(struct zebra_early_route *ere)
if (ere->re_nhe)
zebra_nhg_free(ere->re_nhe);

zapi_re_opaque_free(ere->re->opaque);
XFREE(MTYPE_RE, ere->re);
zebra_rib_route_entry_free(ere->re);
XFREE(MTYPE_WQ_WRAPPER, ere);
}

Expand Down Expand Up @@ -4070,9 +4069,7 @@ void rib_unlink(struct route_node *rn, struct route_entry *re)

rib_re_nhg_free(re);

zapi_re_opaque_free(re->opaque);

XFREE(MTYPE_RE, re);
zebra_rib_route_entry_free(re);
}

void rib_delnode(struct route_node *rn, struct route_entry *re)
Expand Down Expand Up @@ -4319,6 +4316,7 @@ struct route_entry *zebra_rib_route_entry_new(vrf_id_t vrf_id, int type,

void zebra_rib_route_entry_free(struct route_entry *re)
{
zapi_re_opaque_free(re->opaque);
XFREE(MTYPE_RE, re);
}

Expand Down Expand Up @@ -4389,7 +4387,7 @@ int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p,

/* In error cases, free the route also */
if (ret < 0)
XFREE(MTYPE_RE, re);
zebra_rib_route_entry_free(re);

return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion zebra/zebra_rnh.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ static void free_state(vrf_id_t vrf_id, struct route_entry *re,

/* free RE and nexthops */
zebra_nhg_free(re->nhe);
XFREE(MTYPE_RE, re);
zebra_rib_route_entry_free(re);
}

static void copy_state(struct rnh *rnh, const struct route_entry *re,
Expand Down

0 comments on commit 32b9c30

Please sign in to comment.