diff options
author | Renato Westphal <renato@openbsd.org> | 2018-07-09 21:02:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-09 21:02:47 +0200 |
commit | fbde7f293e6e9e6b5adf0423c494e04600b423d5 (patch) | |
tree | c70c1965875dc07868a6b5bec0a3286249b08759 | |
parent | Merge pull request #2642 from donaldsharp/deprecated (diff) | |
parent | pimd: Remove unnecessary alloc failures (diff) | |
download | frr-fbde7f293e6e9e6b5adf0423c494e04600b423d5.tar.xz frr-fbde7f293e6e9e6b5adf0423c494e04600b423d5.zip |
Merge pull request #2637 from donaldsharp/pim_malloc_me
pimd: Remove unnecessary alloc failures
-rw-r--r-- | pimd/pim_br.c | 9 | ||||
-rw-r--r-- | pimd/pim_iface.c | 73 | ||||
-rw-r--r-- | pimd/pim_ifchannel.c | 6 | ||||
-rw-r--r-- | pimd/pim_igmp.c | 21 | ||||
-rw-r--r-- | pimd/pim_igmpv3.c | 5 | ||||
-rw-r--r-- | pimd/pim_instance.c | 8 | ||||
-rw-r--r-- | pimd/pim_jp_agg.c | 1 | ||||
-rw-r--r-- | pimd/pim_msdp.c | 22 | ||||
-rw-r--r-- | pimd/pim_neighbor.c | 5 | ||||
-rw-r--r-- | pimd/pim_nht.c | 14 | ||||
-rw-r--r-- | pimd/pim_oil.c | 9 | ||||
-rw-r--r-- | pimd/pim_rp.c | 15 | ||||
-rw-r--r-- | pimd/pim_ssmpingd.c | 15 | ||||
-rw-r--r-- | pimd/pim_static.c | 12 | ||||
-rw-r--r-- | pimd/pim_tlv.c | 6 | ||||
-rw-r--r-- | pimd/pim_upstream.c | 5 |
16 files changed, 2 insertions, 224 deletions
diff --git a/pimd/pim_br.c b/pimd/pim_br.c index f297b0591..6184ea12c 100644 --- a/pimd/pim_br.c +++ b/pimd/pim_br.c @@ -64,10 +64,6 @@ void pim_br_set_pmbr(struct prefix_sg *sg, struct in_addr br) if (!pim_br) { pim_br = XCALLOC(MTYPE_PIM_BR, sizeof(*pim_br)); - if (!pim_br) { - zlog_err("PIM XCALLOC(%zu) failure", sizeof(*pim_br)); - return; - } pim_br->sg = *sg; @@ -100,9 +96,4 @@ void pim_br_clear_pmbr(struct prefix_sg *sg) void pim_br_init(void) { pim_br_list = list_new(); - if (!pim_br_list) { - zlog_err("%s: Failure to create pim_br_list", - __PRETTY_FUNCTION__); - return; - } } diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 5c4d99ad4..e075ff5ac 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -75,36 +75,6 @@ void pim_if_terminate(struct pim_instance *pim) return; } -static void *if_list_clean(struct pim_interface *pim_ifp) -{ - struct pim_ifchannel *ch; - - if (pim_ifp->igmp_join_list) - list_delete_and_null(&pim_ifp->igmp_join_list); - - if (pim_ifp->igmp_socket_list) - list_delete_and_null(&pim_ifp->igmp_socket_list); - - if (pim_ifp->pim_neighbor_list) - list_delete_and_null(&pim_ifp->pim_neighbor_list); - - if (pim_ifp->upstream_switch_list) - list_delete_and_null(&pim_ifp->upstream_switch_list); - - if (pim_ifp->sec_addr_list) - list_delete_and_null(&pim_ifp->sec_addr_list); - - while (!RB_EMPTY(pim_ifchannel_rb, &pim_ifp->ifchannel_rb)) { - ch = RB_ROOT(pim_ifchannel_rb, &pim_ifp->ifchannel_rb); - - pim_ifchannel_delete(ch); - } - - XFREE(MTYPE_PIM_INTERFACE, pim_ifp); - - return 0; -} - static void pim_sec_addr_free(struct pim_secondary_addr *sec_addr) { XFREE(MTYPE_PIM_SEC_ADDR, sec_addr); @@ -145,10 +115,6 @@ struct pim_interface *pim_if_new(struct interface *ifp, int igmp, int pim) zassert(!ifp->info); pim_ifp = XCALLOC(MTYPE_PIM_INTERFACE, sizeof(*pim_ifp)); - if (!pim_ifp) { - zlog_err("PIM XCALLOC(%zu) failure", sizeof(*pim_ifp)); - return 0; - } pim_ifp->options = 0; pim_ifp->pim = pim_get_pim_instance(ifp->vrf_id); @@ -186,38 +152,18 @@ struct pim_interface *pim_if_new(struct interface *ifp, int igmp, int pim) /* list of struct igmp_sock */ pim_ifp->igmp_socket_list = list_new(); - if (!pim_ifp->igmp_socket_list) { - zlog_err("%s: failure: igmp_socket_list=list_new()", - __PRETTY_FUNCTION__); - return if_list_clean(pim_ifp); - } pim_ifp->igmp_socket_list->del = (void (*)(void *))igmp_sock_free; /* list of struct pim_neighbor */ pim_ifp->pim_neighbor_list = list_new(); - if (!pim_ifp->pim_neighbor_list) { - zlog_err("%s: failure: pim_neighbor_list=list_new()", - __PRETTY_FUNCTION__); - return if_list_clean(pim_ifp); - } pim_ifp->pim_neighbor_list->del = (void (*)(void *))pim_neighbor_free; pim_ifp->upstream_switch_list = list_new(); - if (!pim_ifp->upstream_switch_list) { - zlog_err("%s: failure: upstream_switch_list=list_new()", - __PRETTY_FUNCTION__); - return if_list_clean(pim_ifp); - } pim_ifp->upstream_switch_list->del = (void (*)(void *))pim_jp_agg_group_list_free; pim_ifp->upstream_switch_list->cmp = pim_jp_agg_group_list_cmp; pim_ifp->sec_addr_list = list_new(); - if (!pim_ifp->sec_addr_list) { - zlog_err("%s: failure: secondary addresslist", - __PRETTY_FUNCTION__); - return if_list_clean(pim_ifp); - } pim_ifp->sec_addr_list->del = (void (*)(void *))pim_sec_addr_free; pim_ifp->sec_addr_list->cmp = (int (*)(void *, void *))pim_sec_addr_comp; @@ -404,8 +350,6 @@ static int pim_sec_addr_add(struct pim_interface *pim_ifp, struct prefix *addr) } sec_addr = XCALLOC(MTYPE_PIM_SEC_ADDR, sizeof(*sec_addr)); - if (!sec_addr) - return changed; changed = 1; sec_addr->addr = *addr; @@ -1286,20 +1230,6 @@ static struct igmp_join *igmp_join_new(struct interface *ifp, } ij = XCALLOC(MTYPE_PIM_IGMP_JOIN, sizeof(*ij)); - if (!ij) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<grp?>", group_addr, group_str, - sizeof(group_str)); - pim_inet4_dump("<src?>", source_addr, source_str, - sizeof(source_str)); - zlog_err( - "%s: XCALLOC(%zu) failure for IGMP group %s source %s on interface %s", - __PRETTY_FUNCTION__, sizeof(*ij), group_str, source_str, - ifp->name); - close(join_fd); - return 0; - } ij->sock_fd = join_fd; ij->group_addr = group_addr; @@ -1325,9 +1255,6 @@ ferr_r pim_if_igmp_join_add(struct interface *ifp, struct in_addr group_addr, if (!pim_ifp->igmp_join_list) { pim_ifp->igmp_join_list = list_new(); - if (!pim_ifp->igmp_join_list) { - return ferr_cfg_invalid("Insufficient memory"); - } pim_ifp->igmp_join_list->del = (void (*)(void *))igmp_join_free; } diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index 5e6b0f10c..e82a7589b 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -520,12 +520,6 @@ struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp, pim_ifp = ifp->info; ch = XCALLOC(MTYPE_PIM_IFCHANNEL, sizeof(*ch)); - if (!ch) { - zlog_warn( - "%s: pim_ifchannel_new() failure for (S,G)=%s on interface %s", - __PRETTY_FUNCTION__, pim_str_sg_dump(sg), ifp->name); - return NULL; - } ch->flags = 0; if ((source_flags & PIM_ENCODE_RPT_BIT) diff --git a/pimd/pim_igmp.c b/pimd/pim_igmp.c index c980f5fcb..42bdd80ce 100644 --- a/pimd/pim_igmp.c +++ b/pimd/pim_igmp.c @@ -860,18 +860,8 @@ static struct igmp_sock *igmp_sock_new(int fd, struct in_addr ifaddr, } igmp = XCALLOC(MTYPE_PIM_IGMP_SOCKET, sizeof(*igmp)); - if (!igmp) { - zlog_warn("%s %s: XCALLOC() failure", __FILE__, - __PRETTY_FUNCTION__); - return 0; - } igmp->igmp_group_list = list_new(); - if (!igmp->igmp_group_list) { - zlog_err("%s %s: failure: igmp_group_list = list_new()", - __FILE__, __PRETTY_FUNCTION__); - return 0; - } igmp->igmp_group_list->del = (void (*)(void *))igmp_group_free; snprintf(hash_name, 64, "IGMP %s hash", ifp->name); @@ -1130,19 +1120,8 @@ struct igmp_group *igmp_add_group_by_addr(struct igmp_sock *igmp, */ group = XCALLOC(MTYPE_PIM_IGMP_GROUP, sizeof(*group)); - if (!group) { - zlog_warn("%s %s: XCALLOC() failure", __FILE__, - __PRETTY_FUNCTION__); - return NULL; /* error, not found, could not create */ - } group->group_source_list = list_new(); - if (!group->group_source_list) { - zlog_warn("%s %s: list_new() failure", __FILE__, - __PRETTY_FUNCTION__); - XFREE(MTYPE_PIM_IGMP_GROUP, group); /* discard group */ - return NULL; /* error, not found, could not initialize */ - } group->group_source_list->del = (void (*)(void *))igmp_source_free; group->t_group_timer = NULL; diff --git a/pimd/pim_igmpv3.c b/pimd/pim_igmpv3.c index 5ccad39b3..b32d71cc0 100644 --- a/pimd/pim_igmpv3.c +++ b/pimd/pim_igmpv3.c @@ -457,11 +457,6 @@ struct igmp_source *source_new(struct igmp_group *group, } src = XCALLOC(MTYPE_PIM_IGMP_GROUP_SOURCE, sizeof(*src)); - if (!src) { - zlog_warn("%s %s: XCALLOC() failure", __FILE__, - __PRETTY_FUNCTION__); - return 0; /* error, not found, could not create */ - } src->t_source_timer = NULL; src->source_group = group; /* back pointer */ diff --git a/pimd/pim_instance.c b/pimd/pim_instance.c index cb70ee790..5121dc94c 100644 --- a/pimd/pim_instance.c +++ b/pimd/pim_instance.c @@ -69,8 +69,6 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf) char hash_name[64]; pim = XCALLOC(MTYPE_PIM_PIM_INSTANCE, sizeof(struct pim_instance)); - if (!pim) - return NULL; pim_if_init(pim); @@ -102,12 +100,6 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf) } pim->static_routes = list_new(); - if (!pim->static_routes) { - zlog_err("%s %s: failure: static_routes=list_new()", __FILE__, - __PRETTY_FUNCTION__); - pim_instance_terminate(pim); - return NULL; - } pim->static_routes->del = (void (*)(void *))pim_static_route_free; pim->send_v6_secondary = 1; diff --git a/pimd/pim_jp_agg.c b/pimd/pim_jp_agg.c index e87dfbca9..c5f5b9c5e 100644 --- a/pimd/pim_jp_agg.c +++ b/pimd/pim_jp_agg.c @@ -329,7 +329,6 @@ void pim_jp_agg_single_upstream_send(struct pim_rpf *rpf, if (first) { groups = list_new(); - jag.sources = list_new(); listnode_add(groups, &jag); diff --git a/pimd/pim_msdp.c b/pimd/pim_msdp.c index e798d70a5..951e74349 100644 --- a/pimd/pim_msdp.c +++ b/pimd/pim_msdp.c @@ -240,11 +240,6 @@ static struct pim_msdp_sa *pim_msdp_sa_new(struct pim_instance *pim, struct pim_msdp_sa *sa; sa = XCALLOC(MTYPE_PIM_MSDP_SA, sizeof(*sa)); - if (!sa) { - zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*sa)); - return NULL; - } sa->pim = pim; sa->sg = *sg; @@ -1069,11 +1064,6 @@ static enum pim_msdp_err pim_msdp_peer_new(struct pim_instance *pim, pim_msdp_enable(pim); mp = XCALLOC(MTYPE_PIM_MSDP_PEER, sizeof(*mp)); - if (!mp) { - zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*mp)); - return PIM_MSDP_ERR_OOM; - } mp->pim = pim; mp->peer = peer_addr; @@ -1277,11 +1267,6 @@ static struct pim_msdp_mg *pim_msdp_mg_new(const char *mesh_group_name) struct pim_msdp_mg *mg; mg = XCALLOC(MTYPE_PIM_MSDP_MG, sizeof(*mg)); - if (!mg) { - zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*mg)); - return NULL; - } mg->mesh_group_name = XSTRDUP(MTYPE_PIM_MSDP_MG_NAME, mesh_group_name); mg->mbr_list = list_new(); @@ -1395,13 +1380,6 @@ enum pim_msdp_err pim_msdp_mg_mbr_add(struct pim_instance *pim, } mbr = XCALLOC(MTYPE_PIM_MSDP_MG_MBR, sizeof(*mbr)); - if (!mbr) { - zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*mbr)); - /* if there are no references to the mg free it */ - pim_msdp_mg_free(pim, mg); - return PIM_MSDP_ERR_OOM; - } mbr->mbr_ip = mbr_ip; listnode_add_sort(mg->mbr_list, mbr); diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c index 20a942b4f..2730f5e7a 100644 --- a/pimd/pim_neighbor.c +++ b/pimd/pim_neighbor.c @@ -305,11 +305,6 @@ pim_neighbor_new(struct interface *ifp, struct in_addr source_addr, zassert(pim_ifp); neigh = XCALLOC(MTYPE_PIM_NEIGHBOR, sizeof(*neigh)); - if (!neigh) { - zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*neigh)); - return 0; - } neigh->creation = pim_time_monotonic_sec(); neigh->source_addr = source_addr; diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index fa6486a83..ac49373da 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -92,10 +92,6 @@ static struct pim_nexthop_cache *pim_nexthop_cache_add(struct pim_instance *pim, pnc = XCALLOC(MTYPE_PIM_NEXTHOP_CACHE, sizeof(struct pim_nexthop_cache)); - if (!pnc) { - zlog_err("%s: NHT PIM XCALLOC failure ", __PRETTY_FUNCTION__); - return NULL; - } pnc->rpf.rpf_addr.family = rpf_addr->rpf_addr.family; pnc->rpf.rpf_addr.prefixlen = rpf_addr->rpf_addr.prefixlen; pnc->rpf.rpf_addr.u.prefix4.s_addr = @@ -140,14 +136,6 @@ int pim_find_or_track_nexthop(struct pim_instance *pim, struct prefix *addr, pnc = pim_nexthop_cache_find(pim, &rpf); if (!pnc) { pnc = pim_nexthop_cache_add(pim, &rpf); - if (!pnc) { - char rpf_str[PREFIX_STRLEN]; - pim_addr_dump("<nht-pnc?>", addr, rpf_str, - sizeof(rpf_str)); - zlog_warn("%s: pnc node allocation failed. addr %s ", - __PRETTY_FUNCTION__, rpf_str); - return 0; - } pim_sendmsg_zebra_rnh(pim, zclient, pnc, ZEBRA_NEXTHOP_REGISTER); if (PIM_DEBUG_PIM_NHT) { @@ -168,7 +156,7 @@ int pim_find_or_track_nexthop(struct pim_instance *pim, struct prefix *addr, if (up != NULL) hash_get(pnc->upstream_hash, up, hash_alloc_intern); - if (pnc && CHECK_FLAG(pnc->flags, PIM_NEXTHOP_VALID)) { + if (CHECK_FLAG(pnc->flags, PIM_NEXTHOP_VALID)) { memcpy(out_pnc, pnc, sizeof(struct pim_nexthop_cache)); return 1; } diff --git a/pimd/pim_oil.c b/pimd/pim_oil.c index d49484f86..f0f336fb7 100644 --- a/pimd/pim_oil.c +++ b/pimd/pim_oil.c @@ -107,11 +107,6 @@ void pim_oil_init(struct pim_instance *pim) pim_oil_equal, hash_name); pim->channel_oil_list = list_new(); - if (!pim->channel_oil_list) { - zlog_err("%s %s: failure: channel_oil_list=list_new()", - __FILE__, __PRETTY_FUNCTION__); - return; - } pim->channel_oil_list->del = (void (*)(void *))pim_channel_oil_free; pim->channel_oil_list->cmp = (int (*)(void *, void *))pim_channel_oil_compare; @@ -182,10 +177,6 @@ struct channel_oil *pim_channel_oil_add(struct pim_instance *pim, } c_oil = XCALLOC(MTYPE_PIM_CHANNEL_OIL, sizeof(*c_oil)); - if (!c_oil) { - zlog_err("PIM XCALLOC(%zu) failure", sizeof(*c_oil)); - return NULL; - } c_oil->oil.mfcc_mcastgrp = sg->grp; c_oil->oil.mfcc_origin = sg->src; diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index a8cf58cd3..7e053d2aa 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -115,13 +115,6 @@ void pim_rp_init(struct pim_instance *pim) rp_info = XCALLOC(MTYPE_PIM_RP, sizeof(*rp_info)); - if (!rp_info) { - zlog_err("Unable to alloc rp_info"); - route_table_finish(pim->rp_table); - list_delete_and_null(&pim->rp_list); - return; - } - if (!str2prefix("224.0.0.0/4", &rp_info->group)) { zlog_err("Unable to convert 224.0.0.0/4 to prefix"); list_delete_and_null(&pim->rp_list); @@ -365,8 +358,6 @@ int pim_rp_new(struct pim_instance *pim, const char *rp, struct route_node *rn; rp_info = XCALLOC(MTYPE_PIM_RP, sizeof(*rp_info)); - if (!rp_info) - return PIM_MALLOC_FAIL; if (group_range == NULL) result = str2prefix("224.0.0.0/4", &rp_info->group); @@ -534,12 +525,6 @@ int pim_rp_new(struct pim_instance *pim, const char *rp, listnode_add_sort(pim->rp_list, rp_info); rn = route_node_get(pim->rp_table, &rp_info->group); - if (!rn) { - char buf[PREFIX_STRLEN]; - zlog_err("Failure to get route node for pim->rp_table: %s", - prefix2str(&rp_info->group, buf, sizeof(buf))); - return PIM_MALLOC_FAIL; - } rn->info = rp_info; if (PIM_DEBUG_TRACE) { diff --git a/pimd/pim_ssmpingd.c b/pimd/pim_ssmpingd.c index 8e7da0f12..bdf303d5c 100644 --- a/pimd/pim_ssmpingd.c +++ b/pimd/pim_ssmpingd.c @@ -348,12 +348,6 @@ static struct ssmpingd_sock *ssmpingd_new(struct pim_instance *pim, if (!pim->ssmpingd_list) { pim->ssmpingd_list = list_new(); - if (!pim->ssmpingd_list) { - zlog_err( - "%s %s: failure: qpim_ssmpingd_list=list_new()", - __FILE__, __PRETTY_FUNCTION__); - return 0; - } pim->ssmpingd_list->del = (void (*)(void *))ssmpingd_free; } @@ -369,15 +363,6 @@ static struct ssmpingd_sock *ssmpingd_new(struct pim_instance *pim, } ss = XCALLOC(MTYPE_PIM_SSMPINGD, sizeof(*ss)); - if (!ss) { - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<src?>", source_addr, source_str, - sizeof(source_str)); - zlog_err("%s: XCALLOC(%zu) failure for ssmpingd source %s", - __PRETTY_FUNCTION__, sizeof(*ss), source_str); - close(sock_fd); - return 0; - } ss->pim = pim; ss->sock_fd = sock_fd; diff --git a/pimd/pim_static.c b/pimd/pim_static.c index 3d44a01c7..9569b7dca 100644 --- a/pimd/pim_static.c +++ b/pimd/pim_static.c @@ -39,14 +39,7 @@ void pim_static_route_free(struct static_route *s_route) static struct static_route *static_route_alloc() { - struct static_route *s_route; - - s_route = XCALLOC(MTYPE_PIM_STATIC_ROUTE, sizeof(*s_route)); - if (!s_route) { - zlog_err("PIM XCALLOC(%zu) failure", sizeof(*s_route)); - return 0; - } - return s_route; + return XCALLOC(MTYPE_PIM_STATIC_ROUTE, sizeof(struct static_route)); } static struct static_route *static_route_new(unsigned int iif, unsigned int oif, @@ -55,9 +48,6 @@ static struct static_route *static_route_new(unsigned int iif, unsigned int oif, { struct static_route *s_route; s_route = static_route_alloc(); - if (!s_route) { - return 0; - } s_route->group = group; s_route->source = source; diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c index eddec3c29..80bda336d 100644 --- a/pimd/pim_tlv.c +++ b/pimd/pim_tlv.c @@ -757,12 +757,6 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, */ if (!*hello_option_addr_list) { *hello_option_addr_list = list_new(); - if (!*hello_option_addr_list) { - zlog_err( - "%s %s: failure: hello_option_addr_list=list_new()", - __FILE__, __PRETTY_FUNCTION__); - return -2; - } (*hello_option_addr_list)->del = (void (*)(void *))prefix_free; } diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index 9329d72ce..e3488b6a6 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -603,11 +603,6 @@ static struct pim_upstream *pim_upstream_new(struct pim_instance *pim, struct pim_upstream *up; up = XCALLOC(MTYPE_PIM_UPSTREAM, sizeof(*up)); - if (!up) { - zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*up)); - return NULL; - } up->sg = *sg; pim_str_sg_set(sg, up->sg_str); |