Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zebra: Do not forget to free opaque data for route entry #16576

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 8 additions & 10 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 Expand Up @@ -2264,9 +2261,10 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)
}
}

void zapi_re_opaque_free(struct re_opaque *opaque)
void zapi_re_opaque_free(struct route_entry *re)
{
XFREE(MTYPE_RE_OPAQUE, opaque);
XFREE(MTYPE_RE_OPAQUE, re->opaque);
re->opaque = NULL;
}

static void zread_route_del(ZAPI_HANDLER_ARGS)
Expand Down
2 changes: 1 addition & 1 deletion zebra/zapi_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ extern int zsend_client_close_notify(struct zserv *client,
int zsend_nhg_notify(uint16_t type, uint16_t instance, uint32_t session_id,
uint32_t id, enum zapi_nhg_notify_owner note);

extern void zapi_re_opaque_free(struct re_opaque *opaque);
extern void zapi_re_opaque_free(struct route_entry *re);

extern int zsend_zebra_srv6_locator_add(struct zserv *client,
struct srv6_locator *loc);
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);
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
Loading