diff options
author | anlan_cs <vic.lan@pica8.com> | 2022-04-21 08:37:12 +0200 |
---|---|---|
committer | anlan_cs <vic.lan@pica8.com> | 2022-05-02 18:41:48 +0200 |
commit | 8e3aae66cec563cee0add26482f279c4aae67cb1 (patch) | |
tree | 8edfdd068eeabbd142cfc7c47a56fcec542110fc /pbrd | |
parent | bgpd: fix memory leak for evpn (diff) | |
download | frr-8e3aae66cec563cee0add26482f279c4aae67cb1.tar.xz frr-8e3aae66cec563cee0add26482f279c4aae67cb1.zip |
*: remove the checking returned value for hash_get()
Firstly, *keep no change* for `hash_get()` with NULL
`alloc_func`.
Only focus on cases with non-NULL `alloc_func` of
`hash_get()`.
Since `hash_get()` with non-NULL `alloc_func` parameter
shall not fail, just ignore the returned value of it.
The returned value must not be NULL.
So in this case, remove the unnecessary checking NULL
or not for the returned value and add `void` in front
of it.
Importantly, also *keep no change* for the two cases with
non-NULL `alloc_func` -
1) Use `assert(<returned_data> == <searching_data>)` to
ensure it is a created node, not a found node.
Refer to `isis_vertex_queue_insert()` of isisd, there
are many examples of this case in isid.
2) Use `<returned_data> != <searching_data>` to judge it
is a found node, then free <searching_data>.
Refer to `aspath_intern()` of bgpd, there are many
examples of this case in bgpd.
Here, <returned_data> is the returned value from `hash_get()`,
and <searching_data> is the data, which is to be put into
hash table.
Signed-off-by: anlan_cs <vic.lan@pica8.com>
Diffstat (limited to 'pbrd')
-rw-r--r-- | pbrd/pbr_nht.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/pbrd/pbr_nht.c b/pbrd/pbr_nht.c index fb0bd7258..cbff4832a 100644 --- a/pbrd/pbr_nht.c +++ b/pbrd/pbr_nht.c @@ -1041,8 +1041,9 @@ static int pbr_nht_individual_nexthop_vrf_handle(struct hash_bucket *b, nhrcvi.nhrc); nhrcvi.nhrc->nexthop.vrf_id = pbr_vrf_id(pnhi->pbr_vrf); - hash_get(pbr_nhrc_hash, nhrcvi.nhrc, - hash_alloc_intern); + (void)hash_get(pbr_nhrc_hash, + nhrcvi.nhrc, + hash_alloc_intern); pbr_send_rnh(&nhrcvi.nhrc->nexthop, true); } } while (nhrcvi.nhrc); @@ -1087,7 +1088,8 @@ static void pbr_nht_nexthop_vrf_handle(struct hash_bucket *b, void *data) if (pnhi.pnhc) { pnhi.pnhc->nexthop.vrf_id = pbr_vrf_id(pbr_vrf); - hash_get(pnhgc->nhh, pnhi.pnhc, hash_alloc_intern); + (void)hash_get(pnhgc->nhh, pnhi.pnhc, + hash_alloc_intern); } else pnhc->nexthop.vrf_id = pbr_vrf_id(pbr_vrf); @@ -1141,11 +1143,11 @@ static void pbr_nht_nexthop_interface_handle(struct hash_bucket *b, void *data) if (nhrc) { hash_release(pbr_nhrc_hash, nhrc); nhrc->nexthop.ifindex = ifp->ifindex; - hash_get(pbr_nhrc_hash, nhrc, hash_alloc_intern); + (void)hash_get(pbr_nhrc_hash, nhrc, hash_alloc_intern); } pnhi.pnhc->nexthop.ifindex = ifp->ifindex; - hash_get(pnhgc->nhh, pnhi.pnhc, hash_alloc_intern); + (void)hash_get(pnhgc->nhh, pnhi.pnhc, hash_alloc_intern); pbr_map_check_interface_nh_group_change(pnhgc->name, ifp, old_ifindex); @@ -1290,7 +1292,7 @@ uint32_t pbr_nht_reserve_next_table_id(struct pbr_nexthop_group_cache *nhgc) nhgc->table_id = pbr_next_unallocated_table_id; /* Mark table id as allocated in id-indexed hash */ - hash_get(pbr_nhg_allocated_id_hash, nhgc, hash_alloc_intern); + (void)hash_get(pbr_nhg_allocated_id_hash, nhgc, hash_alloc_intern); /* Pre-compute the next unallocated table id */ pbr_nht_update_next_unallocated_table_id(); |