]> git.puffer.fish Git - mirror/frr.git/commitdiff
*: ALLOC calls cannot fail
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 14 Jun 2018 12:58:05 +0000 (08:58 -0400)
committerDavid Lamparter <equinox@opensourcerouting.org>
Sat, 11 Aug 2018 15:14:58 +0000 (17:14 +0200)
There is no need to check for failure of a ALLOC call
as that any failure to do so will result in a assert
happening.  So we can safely remove all of this code.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
41 files changed:
bgpd/bgp_aspath.c
bgpd/bgp_labelpool.c
bgpd/bgp_route.c
isisd/dict.c
isisd/isis_circuit.c
isisd/isis_spf.c
isisd/isis_te.c
lib/command.c
lib/workqueue.c
nhrpd/nhrp_cache.c
nhrpd/nhrp_interface.c
nhrpd/nhrp_nhs.c
nhrpd/nhrp_peer.c
nhrpd/nhrp_vc.c
nhrpd/zbuf.c
ospf6d/ospf6_interface.c
ospf6d/ospf6_message.c
ospf6d/ospf6_neighbor.c
ospf6d/ospf6_spf.c
ospfclient/ospf_apiclient.c
ospfd/ospf_apiserver.c
ospfd/ospf_ext.c
ospfd/ospf_interface.c
ospfd/ospf_lsa.c
ospfd/ospf_opaque.c
ospfd/ospf_spf.c
ospfd/ospf_sr.c
ospfd/ospf_te.c
pbrd/pbr_zebra.c
pimd/pim_br.c
pimd/pim_cmd.c
pimd/pim_igmpv3.c
pimd/pim_rp.c
pimd/pimd.h
ripd/ripd.c
zebra/if_ioctl_solaris.c
zebra/label_manager.c
zebra/zebra_mpls.c
zebra/zebra_rib.c
zebra/zebra_routemap.c
zebra/zebra_vxlan.c

index 05e67baa8a83140277a6274568e1e755034eae4c..d6ad52b3a6eb9e5799645e91de115a56151ae3f6 100644 (file)
@@ -214,16 +214,11 @@ static struct assegment *assegment_append_asns(struct assegment *seg,
        newas = XREALLOC(MTYPE_AS_SEG_DATA, seg->as,
                         ASSEGMENT_DATA_SIZE(seg->length + num, 1));
 
-       if (newas) {
-               seg->as = newas;
-               memcpy(seg->as + seg->length, asnos,
-                      ASSEGMENT_DATA_SIZE(num, 1));
-               seg->length += num;
-               return seg;
-       }
-
-       assegment_free_all(seg);
-       return NULL;
+       seg->as = newas;
+       memcpy(seg->as + seg->length, asnos,
+              ASSEGMENT_DATA_SIZE(num, 1));
+       seg->length += num;
+       return seg;
 }
 
 static int int_cmp(const void *p1, const void *p2)
index 2c98cd9ef9fb97d30a3d90405c351e921a8131c5..e052d6061ef4dcab729cb301d4c62974a365dab4 100644 (file)
@@ -202,10 +202,6 @@ void bgp_lp_init(struct thread_master *master, struct labelpool *pool)
        lp->requests = XCALLOC(MTYPE_BGP_LABEL_FIFO, sizeof(struct lp_fifo));
        LABEL_FIFO_INIT(lp->requests);
        lp->callback_q = work_queue_new(master, "label callbacks");
-       if (!lp->callback_q) {
-               zlog_err("%s: Failed to allocate work queue", __func__);
-               exit(1);
-       }
 
        lp->callback_q->spec.workfunc = lp_cbq_docallback;
        lp->callback_q->spec.del_item_data = lp_cbq_item_free;
index b66a913f54e43fe46a50e3bc167f74f7be1e381c..d0dbb4221dd881fc532d38721acf904017e4cf98 100644 (file)
@@ -2459,16 +2459,10 @@ static void bgp_processq_del(struct work_queue *wq, void *data)
 
 void bgp_process_queue_init(void)
 {
-       if (!bm->process_main_queue) {
+       if (!bm->process_main_queue)
                bm->process_main_queue =
                        work_queue_new(bm->master, "process_main_queue");
 
-               if (!bm->process_main_queue) {
-                       zlog_err("%s: Failed to allocate work queue", __func__);
-                       exit(1);
-               }
-       }
-
        bm->process_main_queue->spec.workfunc = &bgp_process_wq;
        bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
        bm->process_main_queue->spec.max_retries = 0;
@@ -3838,11 +3832,7 @@ static void bgp_clear_node_queue_init(struct peer *peer)
        snprintf(wname, sizeof(wname), "clear %s", peer->host);
 #undef CLEAR_QUEUE_NAME_LEN
 
-       if ((peer->clear_node_queue = work_queue_new(bm->master, wname))
-           == NULL) {
-               zlog_err("%s: Failed to allocate work queue", __func__);
-               exit(1);
-       }
+       peer->clear_node_queue = work_queue_new(bm->master, wname);
        peer->clear_node_queue->spec.hold = 10;
        peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
        peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
index 20a4c0ff7383fe31d7199482ff186d797b2bf2e1..5d3e61e6d6bfe0915f0edd55d80a32b646586ec9 100644 (file)
@@ -244,19 +244,18 @@ dict_t *dict_create(dictcount_t maxcount, dict_comp_t comp)
 {
        dict_t *new = XCALLOC(MTYPE_ISIS_DICT, sizeof(dict_t));
 
-       if (new) {
-               new->compare = comp;
-               new->allocnode = dnode_alloc;
-               new->freenode = dnode_free;
-               new->context = NULL;
-               new->nodecount = 0;
-               new->maxcount = maxcount;
-               new->nilnode.left = &new->nilnode;
-               new->nilnode.right = &new->nilnode;
-               new->nilnode.parent = &new->nilnode;
-               new->nilnode.color = dnode_black;
-               new->dupes = 0;
-       }
+       new->compare = comp;
+       new->allocnode = dnode_alloc;
+       new->freenode = dnode_free;
+       new->context = NULL;
+       new->nodecount = 0;
+       new->maxcount = maxcount;
+       new->nilnode.left = &new->nilnode;
+       new->nilnode.right = &new->nilnode;
+       new->nilnode.parent = &new->nilnode;
+       new->nilnode.color = dnode_black;
+       new->dupes = 0;
+
        return new;
 }
 
@@ -974,12 +973,12 @@ static void dnode_free(dnode_t *node, void *context)
 dnode_t *dnode_create(void *data)
 {
        dnode_t *new = XCALLOC(MTYPE_ISIS_DICT_NODE, sizeof(dnode_t));
-       if (new) {
-               new->data = data;
-               new->parent = NULL;
-               new->left = NULL;
-               new->right = NULL;
-       }
+
+       new->data = data;
+       new->parent = NULL;
+       new->left = NULL;
+       new->right = NULL;
+
        return new;
 }
 
@@ -1250,8 +1249,8 @@ static char *dupstring(char *str)
 {
        int sz = strlen(str) + 1;
        char *new = XCALLOC(MTYPE_ISIS_TMP, sz);
-       if (new)
-               memcpy(new, str, sz);
+
+       memcpy(new, str, sz);
        return new;
 }
 
index d51f31ff3728d7055848e5ee27cba29675c77ec9..42041a7c46770c6c0a18378b5440452651f72bca 100644 (file)
@@ -73,10 +73,6 @@ struct isis_circuit *isis_circuit_new()
        int i;
 
        circuit = XCALLOC(MTYPE_ISIS_CIRCUIT, sizeof(struct isis_circuit));
-       if (circuit == NULL) {
-               zlog_err("Can't malloc isis circuit");
-               return NULL;
-       }
 
        /*
         * Default values
index 0a8b0e927e5a0f34322aa21e81b54e5314b44dca..63f8b34bed7c5d9b703191511dd0d2b1aaa8d5d6 100644 (file)
@@ -486,10 +486,6 @@ struct isis_spftree *isis_spftree_new(struct isis_area *area)
        struct isis_spftree *tree;
 
        tree = XCALLOC(MTYPE_ISIS_SPFTREE, sizeof(struct isis_spftree));
-       if (tree == NULL) {
-               zlog_err("ISIS-Spf: isis_spftree_new Out of memory!");
-               return NULL;
-       }
 
        isis_vertex_queue_init(&tree->tents, "IS-IS SPF tents", true);
        isis_vertex_queue_init(&tree->paths, "IS-IS SPF paths", false);
index 8e53df3b61fe5dfb8c46e172772f9110a45c3af7..44ba64ce26f80f76d3a3064b9241560fa4f41681 100644 (file)
@@ -87,9 +87,6 @@ struct mpls_te_circuit *mpls_te_circuit_new()
 
        mtc = XCALLOC(MTYPE_ISIS_MPLS_TE, sizeof(struct mpls_te_circuit));
 
-       if (mtc == NULL)
-               return NULL;
-
        mtc->status = disable;
        mtc->type = STD_TE;
        mtc->length = 0;
index 0bf856f2484b4ac07d74466629e11f6f92982723..a98654dd23311c93bf7cf6d5f9629923f2c401e4 100644 (file)
@@ -2409,11 +2409,7 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel)
                        return CMD_WARNING_CONFIG_FAILED;
                }
 
-               if ((p = XMALLOC(MTYPE_TMP, strlen(cwd) + strlen(fname) + 2))
-                   == NULL) {
-                       zlog_err("config_log_file: Unable to alloc mem!");
-                       return CMD_WARNING_CONFIG_FAILED;
-               }
+               p = XMALLOC(MTYPE_TMP, strlen(cwd) + strlen(fname) + 2);
                sprintf(p, "%s/%s", cwd, fname);
                fullpath = p;
        } else
index 39dd142afb9d69f3f837332b2932a0e69d2ad47a..c927d5d714118c4745a99cb6358e518f8ae6ba88 100644 (file)
@@ -81,9 +81,6 @@ struct work_queue *work_queue_new(struct thread_master *m,
 
        new = XCALLOC(MTYPE_WORK_QUEUE, sizeof(struct work_queue));
 
-       if (new == NULL)
-               return new;
-
        new->name = XSTRDUP(MTYPE_WORK_QUEUE_NAME, queue_name);
        new->master = m;
        SET_FLAG(new->flags, WQ_UNPLUGGED);
@@ -152,10 +149,7 @@ void work_queue_add(struct work_queue *wq, void *data)
 
        assert(wq);
 
-       if (!(item = work_queue_item_new(wq))) {
-               zlog_err("%s: unable to get new queue item", __func__);
-               return;
-       }
+       item = work_queue_item_new(wq);
 
        item->data = data;
        work_queue_item_enqueue(wq, item);
index ffc8b5a9bf80a7295e5415377dbf173d73e94d1b..f3a33eb28f2cda76876ec533f2bf21e788461199 100644 (file)
@@ -48,17 +48,16 @@ static void *nhrp_cache_alloc(void *data)
        struct nhrp_cache *p, *key = data;
 
        p = XMALLOC(MTYPE_NHRP_CACHE, sizeof(struct nhrp_cache));
-       if (p) {
-               *p = (struct nhrp_cache){
-                       .cur.type = NHRP_CACHE_INVALID,
-                       .new.type = NHRP_CACHE_INVALID,
-                       .remote_addr = key->remote_addr,
-                       .ifp = key->ifp,
-                       .notifier_list =
-                               NOTIFIER_LIST_INITIALIZER(&p->notifier_list),
-               };
-               nhrp_cache_counts[p->cur.type]++;
-       }
+
+       *p = (struct nhrp_cache){
+               .cur.type = NHRP_CACHE_INVALID,
+               .new.type = NHRP_CACHE_INVALID,
+               .remote_addr = key->remote_addr,
+               .ifp = key->ifp,
+               .notifier_list =
+               NOTIFIER_LIST_INITIALIZER(&p->notifier_list),
+       };
+       nhrp_cache_counts[p->cur.type]++;
 
        return p;
 }
index 054a375cb89a2b5fae1f00867112fbcc868136e5..3a42712748cd3b768820f0f0ca7d60df4c39cc96 100644 (file)
@@ -25,8 +25,6 @@ static int nhrp_if_new_hook(struct interface *ifp)
        afi_t afi;
 
        nifp = XCALLOC(MTYPE_NHRP_IF, sizeof(struct nhrp_interface));
-       if (!nifp)
-               return 0;
 
        ifp->info = nifp;
        nifp->ifp = ifp;
index a7a8c20191541d326828f3bf4d228d2b30d0de5e..360972c327f54cb98038a0b648c6ff1a9c9cc516 100644 (file)
@@ -324,8 +324,6 @@ int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr,
        }
 
        nhs = XMALLOC(MTYPE_NHRP_NHS, sizeof(struct nhrp_nhs));
-       if (!nhs)
-               return NHRP_ERR_NO_MEMORY;
 
        *nhs = (struct nhrp_nhs){
                .afi = afi,
index 8952a282e904ec42ada73237da520bc0b29c1525..44271d68ac7930697598e388b784d4a0aa51bc6d 100644 (file)
@@ -165,18 +165,18 @@ static void *nhrp_peer_create(void *data)
        struct nhrp_peer *p, *key = data;
 
        p = XMALLOC(MTYPE_NHRP_PEER, sizeof(*p));
-       if (p) {
-               *p = (struct nhrp_peer){
-                       .ref = 0,
-                       .ifp = key->ifp,
-                       .vc = key->vc,
-                       .notifier_list =
-                               NOTIFIER_LIST_INITIALIZER(&p->notifier_list),
-               };
-               nhrp_vc_notify_add(p->vc, &p->vc_notifier, nhrp_peer_vc_notify);
-               nhrp_interface_notify_add(p->ifp, &p->ifp_notifier,
-                                         nhrp_peer_ifp_notify);
-       }
+
+       *p = (struct nhrp_peer){
+               .ref = 0,
+               .ifp = key->ifp,
+               .vc = key->vc,
+               .notifier_list =
+               NOTIFIER_LIST_INITIALIZER(&p->notifier_list),
+       };
+       nhrp_vc_notify_add(p->vc, &p->vc_notifier, nhrp_peer_vc_notify);
+       nhrp_interface_notify_add(p->ifp, &p->ifp_notifier,
+                                 nhrp_peer_ifp_notify);
+
        return p;
 }
 
index c373411d66d9694a68597a74a2c25c5743295020..41a87d4adbc181c0170ae450da8d633158b53354 100644 (file)
@@ -48,14 +48,13 @@ static void *nhrp_vc_alloc(void *data)
        struct nhrp_vc *vc, *key = data;
 
        vc = XMALLOC(MTYPE_NHRP_VC, sizeof(struct nhrp_vc));
-       if (vc) {
-               *vc = (struct nhrp_vc){
-                       .local.nbma = key->local.nbma,
-                       .remote.nbma = key->remote.nbma,
-                       .notifier_list =
-                               NOTIFIER_LIST_INITIALIZER(&vc->notifier_list),
-               };
-       }
+
+       *vc = (struct nhrp_vc){
+               .local.nbma = key->local.nbma,
+               .remote.nbma = key->remote.nbma,
+               .notifier_list =
+               NOTIFIER_LIST_INITIALIZER(&vc->notifier_list),
+       };
 
        return vc;
 }
@@ -118,8 +117,6 @@ int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc)
                        return 0;
 
                sa = XMALLOC(MTYPE_NHRP_VC, sizeof(struct child_sa));
-               if (!sa)
-                       return 0;
 
                *sa = (struct child_sa){
                        .id = child_id,
index 65232a309318b4cb9deae4e17195b6a87ea6ab41..6e7cad8aec2c5940fbfc538d8c5b910187db04f6 100644 (file)
@@ -25,8 +25,6 @@ struct zbuf *zbuf_alloc(size_t size)
        struct zbuf *zb;
 
        zb = XMALLOC(MTYPE_ZBUF_DATA, sizeof(*zb) + size);
-       if (!zb)
-               return NULL;
 
        zbuf_init(zb, zb + 1, size, 0);
        zb->allocated = 1;
index 9178bf2f6a5776ee5e1b6db4c31d2bb9294dd278..9777a01ae6d665d09f2e8046707b7d49920f3bfc 100644 (file)
@@ -180,12 +180,6 @@ struct ospf6_interface *ospf6_interface_create(struct interface *ifp)
        oi = (struct ospf6_interface *)XCALLOC(MTYPE_OSPF6_IF,
                                               sizeof(struct ospf6_interface));
 
-       if (!oi) {
-               zlog_err("Can't malloc ospf6_interface for ifindex %d",
-                        ifp->ifindex);
-               return (struct ospf6_interface *)NULL;
-       }
-
        oi->area = (struct ospf6_area *)NULL;
        oi->neighbor_list = list_new();
        oi->neighbor_list->cmp = ospf6_neighbor_cmp;
index c608a0110243db8932528d49311e2a9e47c24c87..c7cd94bd327bb90a4e8e743f41cd7da7657bb1d9 100644 (file)
@@ -1503,14 +1503,6 @@ int ospf6_iobuf_size(unsigned int size)
 
        recvnew = XMALLOC(MTYPE_OSPF6_MESSAGE, size);
        sendnew = XMALLOC(MTYPE_OSPF6_MESSAGE, size);
-       if (recvnew == NULL || sendnew == NULL) {
-               if (recvnew)
-                       XFREE(MTYPE_OSPF6_MESSAGE, recvnew);
-               if (sendnew)
-                       XFREE(MTYPE_OSPF6_MESSAGE, sendnew);
-               zlog_debug("Could not allocate I/O buffer of size %d.", size);
-               return iobuflen;
-       }
 
        if (recvbuf)
                XFREE(MTYPE_OSPF6_MESSAGE, recvbuf);
index b5a1812ffa823f9b849eac7170096991f8127823..0cc7294d67995cae0bb0037da7edda552c15fbf0 100644 (file)
@@ -84,10 +84,6 @@ struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id,
 
        on = (struct ospf6_neighbor *)XMALLOC(MTYPE_OSPF6_NEIGHBOR,
                                              sizeof(struct ospf6_neighbor));
-       if (on == NULL) {
-               zlog_warn("neighbor: malloc failed");
-               return NULL;
-       }
 
        memset(on, 0, sizeof(struct ospf6_neighbor));
        inet_ntop(AF_INET, &router_id, buf, sizeof(buf));
index 5b6691e6bf1b4039f9724a2130d019d18a59cd68..69c18ab7509429b8ccee14cb6e6594ec3f3e79c3 100644 (file)
@@ -1012,16 +1012,10 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area,
 
        /* Allocate memory for this LSA */
        new_header = XMALLOC(MTYPE_OSPF6_LSA_HEADER, total_lsa_length);
-       if (!new_header)
-               return NULL;
 
        /* LSA information structure */
        lsa = (struct ospf6_lsa *)XCALLOC(MTYPE_OSPF6_LSA,
                                          sizeof(struct ospf6_lsa));
-       if (!lsa) {
-               free(new_header);
-               return NULL;
-       }
 
        lsa->header = (struct ospf6_lsa_header *)new_header;
 
index 5b46059d7835d14868bc6e2a8e38d4d0d4a7fead..db624ae0741aaefaae71579a15e8198e6a8fb20f 100644 (file)
@@ -570,10 +570,7 @@ static void ospf_apiclient_handle_lsa_update(struct ospf_apiclient *oclient,
        /* Extract LSA from message */
        lsalen = ntohs(cn->data.length);
        lsa = XMALLOC(MTYPE_OSPF_APICLIENT, lsalen);
-       if (!lsa) {
-               fprintf(stderr, "LSA update: Cannot allocate memory for LSA\n");
-               return;
-       }
+
        memcpy(lsa, &(cn->data), lsalen);
 
        /* Invoke registered update callback function */
@@ -598,10 +595,7 @@ static void ospf_apiclient_handle_lsa_delete(struct ospf_apiclient *oclient,
        /* Extract LSA from message */
        lsalen = ntohs(cn->data.length);
        lsa = XMALLOC(MTYPE_OSPF_APICLIENT, lsalen);
-       if (!lsa) {
-               fprintf(stderr, "LSA delete: Cannot allocate memory for LSA\n");
-               return;
-       }
+
        memcpy(lsa, &(cn->data), lsalen);
 
        /* Invoke registered update callback function */
index 8f8900e147fee286bc442f9d970055d35674655a..c0ce971f0cbd6fd5d7520a2096e934fbb6f9ffb1 100644 (file)
@@ -1176,13 +1176,11 @@ int ospf_apiserver_handle_register_event(struct ospf_apiserver *apiserv,
 
        apiserv->filter =
                XMALLOC(MTYPE_OSPF_APISERVER_MSGFILTER, ntohs(msg->hdr.msglen));
-       if (apiserv->filter) {
-               /* copy it over. */
-               memcpy(apiserv->filter, &rmsg->filter, ntohs(msg->hdr.msglen));
-               rc = OSPF_API_OK;
-       } else {
-               rc = OSPF_API_NOMEMORY;
-       }
+
+       /* copy it over. */
+       memcpy(apiserv->filter, &rmsg->filter, ntohs(msg->hdr.msglen));
+       rc = OSPF_API_OK;
+
        /* Send a reply back to client with return code */
        rc = ospf_apiserver_send_reply(apiserv, seqnum, rc);
        return rc;
index 331cba44a8e446778805f43c2cee710bbc139bb1..b8d14c351ee38b1a82aa494fac7dead90144ccbc 100644 (file)
@@ -545,11 +545,6 @@ static int ospf_ext_link_new_if(struct interface *ifp)
        }
 
        new = XCALLOC(MTYPE_OSPF_EXT_PARAMS, sizeof(struct ext_itf));
-       if (new == NULL) {
-               zlog_warn("EXT (%s): XCALLOC: %s", __func__,
-                         safe_strerror(errno));
-               return rc;
-       }
 
        /* initialize new information and link back the interface */
        new->ifp = ifp;
index 23353b3c309f089a3e124ac5ff2ab2fb90bf364d..24584f671312912113614856b7eb4c90de5a1d11 100644 (file)
@@ -523,9 +523,6 @@ static struct ospf_if_params *ospf_new_if_params(void)
 
        oip = XCALLOC(MTYPE_OSPF_IF_PARAMS, sizeof(struct ospf_if_params));
 
-       if (!oip)
-               return NULL;
-
        UNSET_IF_PARAM(oip, output_cost_cmd);
        UNSET_IF_PARAM(oip, transmit_delay);
        UNSET_IF_PARAM(oip, retransmit_interval);
index 416533883457f33dc68add33e58e97caf7023c11..2651cf717b82355c9d83190db21752394ec795be 100644 (file)
@@ -2912,24 +2912,17 @@ void ospf_lsa_maxage(struct ospf *ospf, struct ospf_lsa *lsa)
        lsa_prefix.prefixlen = sizeof(lsa_prefix.u.ptr) * CHAR_BIT;
        lsa_prefix.u.ptr = (uintptr_t)lsa;
 
-       if ((rn = route_node_get(ospf->maxage_lsa,
-                                (struct prefix *)&lsa_prefix))
-           != NULL) {
-               if (rn->info != NULL) {
-                       if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
-                               zlog_debug(
-                                       "LSA[%s]: found LSA (%p) in table for LSA %p %d",
-                                       dump_lsa_key(lsa), rn->info,
-                                       (void *)lsa, lsa_prefix.prefixlen);
-                       route_unlock_node(rn);
-               } else {
-                       rn->info = ospf_lsa_lock(lsa);
-                       SET_FLAG(lsa->flags, OSPF_LSA_IN_MAXAGE);
-               }
+       rn = route_node_get(ospf->maxage_lsa, (struct prefix *)&lsa_prefix);
+       if (rn->info != NULL) {
+               if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
+                       zlog_debug(
+                                  "LSA[%s]: found LSA (%p) in table for LSA %p %d",
+                                  dump_lsa_key(lsa), rn->info,
+                                  (void *)lsa, lsa_prefix.prefixlen);
+               route_unlock_node(rn);
        } else {
-               zlog_err("Unable to allocate memory for maxage lsa %s\n",
-                        dump_lsa_key(lsa));
-               assert(0);
+               rn->info = ospf_lsa_lock(lsa);
+               SET_FLAG(lsa->flags, OSPF_LSA_IN_MAXAGE);
        }
 
        if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
index 1ae9a29a1b509d0190744be4989274fd970a1b7f..be62eb3906d08bcdea1f5b3b7201d156bd4abfa6 100644 (file)
@@ -399,13 +399,8 @@ int ospf_register_opaque_functab(
                        }
        }
 
-       if ((new = XCALLOC(MTYPE_OSPF_OPAQUE_FUNCTAB,
-                          sizeof(struct ospf_opaque_functab)))
-           == NULL) {
-               zlog_warn("ospf_register_opaque_functab: XMALLOC: %s",
-                         safe_strerror(errno));
-               goto out;
-       }
+       new = XCALLOC(MTYPE_OSPF_OPAQUE_FUNCTAB,
+                     sizeof(struct ospf_opaque_functab));
 
        new->opaque_type = opaque_type;
        new->oipt = NULL;
@@ -554,13 +549,8 @@ register_opaque_info_per_type(struct ospf_opaque_functab *functab,
        struct ospf *top;
        struct opaque_info_per_type *oipt;
 
-       if ((oipt = XCALLOC(MTYPE_OPAQUE_INFO_PER_TYPE,
-                           sizeof(struct opaque_info_per_type)))
-           == NULL) {
-               zlog_warn("register_opaque_info_per_type: XMALLOC: %s",
-                         safe_strerror(errno));
-               goto out;
-       }
+       oipt = XCALLOC(MTYPE_OPAQUE_INFO_PER_TYPE,
+                      sizeof(struct opaque_info_per_type));
 
        switch (new->data->type) {
        case OSPF_OPAQUE_LINK_LSA:
@@ -711,13 +701,9 @@ register_opaque_info_per_id(struct opaque_info_per_type *oipt,
 {
        struct opaque_info_per_id *oipi;
 
-       if ((oipi = XCALLOC(MTYPE_OPAQUE_INFO_PER_ID,
-                           sizeof(struct opaque_info_per_id)))
-           == NULL) {
-               zlog_warn("register_opaque_info_per_id: XMALLOC: %s",
-                         safe_strerror(errno));
-               goto out;
-       }
+       oipi = XCALLOC(MTYPE_OPAQUE_INFO_PER_ID,
+                      sizeof(struct opaque_info_per_id));
+
        oipi->opaque_id = GET_OPAQUE_ID(ntohl(new->data->id.s_addr));
        oipi->t_opaque_lsa_self = NULL;
        oipi->opqctl_type = oipt;
@@ -725,7 +711,6 @@ register_opaque_info_per_id(struct opaque_info_per_type *oipt,
 
        listnode_add(oipt->id_list, oipi);
 
-out:
        return oipi;
 }
 
index c6c16e71693ae1e5fab96d7d274a08b6e5da92b9..e3c729f65ee14895d5846ea2e911e2b18097bb1c 100644 (file)
@@ -154,9 +154,6 @@ static struct vertex_parent *vertex_parent_new(struct vertex *v, int backlink,
 
        new = XMALLOC(MTYPE_OSPF_VERTEX_PARENT, sizeof(struct vertex_parent));
 
-       if (new == NULL)
-               return NULL;
-
        new->parent = v;
        new->backlink = backlink;
        new->nexthop = hop;
index e5fc3e29548e740b015310f9252313970b929f00..25983ddc57c142efe49cfe5049c7f4d65a6b93c4 100644 (file)
@@ -128,12 +128,6 @@ static struct sr_node *sr_node_new(struct in_addr *rid)
        /* Allocate Segment Routing node memory */
        new = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_node));
 
-       /* Sanity Check */
-       if (new == NULL) {
-               zlog_err("SR (%s): Abort! can't create new SR node", __func__);
-               return NULL;
-       }
-
        /* Default Algorithm, SRGB and MSD */
        for (int i = 0; i < ALGORITHM_COUNT; i++)
                new->algo[i] = SR_ALGORITHM_UNSET;
@@ -735,9 +729,6 @@ static struct sr_link *get_ext_link_sid(struct tlv_header *tlvh)
 
        srl = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_link));
 
-       if (srl == NULL)
-               return NULL;
-
        /* Initialize TLV browsing */
        length = ntohs(tlvh->length) - EXT_TLV_LINK_SIZE;
        sub_tlvh = (struct tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE
@@ -820,9 +811,6 @@ static struct sr_prefix *get_ext_prefix_sid(struct tlv_header *tlvh)
 
        srp = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_prefix));
 
-       if (srp == NULL)
-               return NULL;
-
        /* Initialize TLV browsing */
        length = ntohs(tlvh->length) - EXT_TLV_PREFIX_SIZE;
        sub_tlvh = (struct tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE
index 86125d0c769fcb11ea3e55da2295ddbc59999fc8..cc2d9282fe14c024427fef124a237345364ba7b4 100644 (file)
@@ -857,11 +857,6 @@ static int ospf_mpls_te_new_if(struct interface *ifp)
        }
 
        new = XCALLOC(MTYPE_OSPF_MPLS_TE, sizeof(struct mpls_te_link));
-       if (new == NULL) {
-               zlog_warn("ospf_mpls_te_new_if: XMALLOC: %s",
-                         safe_strerror(errno));
-               return rc;
-       }
 
        new->instance = get_mpls_te_instance_value();
        new->ifp = ifp;
index 8d336c9d0d95b3b98984e93caaf62a910cc56027..25d64238bfd3b6ced06a290e6795e8bad96d93db 100644 (file)
@@ -54,12 +54,6 @@ struct pbr_interface *pbr_if_new(struct interface *ifp)
 
        pbr_ifp = XCALLOC(MTYPE_PBR_INTERFACE, sizeof(*pbr_ifp));
 
-       if (!pbr_ifp) {
-               zlog_err("%s: PBR XCALLOC(%zu) failure", __PRETTY_FUNCTION__,
-                        sizeof(*pbr_ifp));
-               return 0;
-       }
-
        ifp->info = pbr_ifp;
        return pbr_ifp;
 }
index 6184ea12c416706a7b6339d8e21c0212ba525a10..fc6a02ec9316c8a7d8632dcc53f278cf7be15325 100644 (file)
@@ -64,7 +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));
-
                pim_br->sg = *sg;
 
                listnode_add(pim_br_list, pim_br);
index 460bbfeae71e6cffafef255ae37c429a5d9a5c1d..15717aa7a4bd7203e03a512c3300b172a5547717 100644 (file)
@@ -5106,11 +5106,6 @@ static int pim_rp_cmd_worker(struct pim_instance *pim, struct vty *vty,
 
        result = pim_rp_new(pim, rp, group, plist);
 
-       if (result == PIM_MALLOC_FAIL) {
-               vty_out(vty, "%% Out of memory\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
        if (result == PIM_GROUP_BAD_ADDRESS) {
                vty_out(vty, "%% Bad group address specified: %s\n", group);
                return CMD_WARNING_CONFIG_FAILED;
index b32d71cc0d216ec6ad56cd03c46e5514b08ac8c7..132fe4d56424e3c45394e779ab464d6b1e1d88a8 100644 (file)
@@ -486,9 +486,6 @@ static struct igmp_source *add_source_by_addr(struct igmp_sock *igmp,
        }
 
        src = source_new(group, src_addr);
-       if (!src) {
-               return 0;
-       }
 
        return src;
 }
@@ -579,10 +576,6 @@ static void isex_excl(struct igmp_group *group, int num_sources,
                        /* E.4: if not found, create source with timer=GMI:
                         * (A-X-Y) */
                        source = source_new(group, *src_addr);
-                       if (!source) {
-                               /* ugh, internal malloc failure, skip source */
-                               continue;
-                       }
                        zassert(!source->t_source_timer); /* timer == 0 */
                        igmp_source_reset_gmi(group->group_igmp_sock, group,
                                              source);
@@ -637,10 +630,6 @@ static void isex_incl(struct igmp_group *group, int num_sources,
                        /* I.4: if not found, create source with timer=0 (B-A)
                         */
                        source = source_new(group, *src_addr);
-                       if (!source) {
-                               /* ugh, internal malloc failure, skip source */
-                               continue;
-                       }
                        zassert(!source->t_source_timer); /* (B-A) timer=0 */
                }
 
@@ -720,10 +709,6 @@ static void toin_incl(struct igmp_group *group, int num_sources,
                } else {
                        /* If not found, create new source */
                        source = source_new(group, *src_addr);
-                       if (!source) {
-                               /* ugh, internal malloc failure, skip source */
-                               continue;
-                       }
                }
 
                /* (B)=GMI */
@@ -765,10 +750,6 @@ static void toin_excl(struct igmp_group *group, int num_sources,
                } else {
                        /* If not found, create new source */
                        source = source_new(group, *src_addr);
-                       if (!source) {
-                               /* ugh, internal malloc failure, skip source */
-                               continue;
-                       }
                }
 
                /* (A)=GMI */
@@ -854,10 +835,6 @@ static void toex_incl(struct igmp_group *group, int num_sources,
                        /* If source not found, create source with timer=0:
                         * (B-A)=0 */
                        source = source_new(group, *src_addr);
-                       if (!source) {
-                               /* ugh, internal malloc failure, skip source */
-                               continue;
-                       }
                        zassert(!source->t_source_timer); /* (B-A) timer=0 */
                }
 
@@ -917,10 +894,6 @@ static void toex_excl(struct igmp_group *group, int num_sources,
                         * (A-X-Y)=Group Timer */
                        long group_timer_msec;
                        source = source_new(group, *src_addr);
-                       if (!source) {
-                               /* ugh, internal malloc failure, skip source */
-                               continue;
-                       }
 
                        zassert(!source->t_source_timer); /* timer == 0 */
                        group_timer_msec = igmp_group_timer_remain_msec(group);
@@ -1431,10 +1404,6 @@ static void block_excl(struct igmp_group *group, int num_sources,
                         * (A-X-Y)=Group Timer */
                        long group_timer_msec;
                        source = source_new(group, *src_addr);
-                       if (!source) {
-                               /* ugh, internal malloc failure, skip source */
-                               continue;
-                       }
 
                        zassert(!source->t_source_timer); /* timer == 0 */
                        group_timer_msec = igmp_group_timer_remain_msec(group);
index 783f9317522acc30dc14f1b739f444f4cb3ac186..3b3e5eb693c6a575144d3f5669f1ccedcce4b900 100644 (file)
@@ -102,19 +102,10 @@ void pim_rp_init(struct pim_instance *pim)
        struct route_node *rn;
 
        pim->rp_list = list_new();
-       if (!pim->rp_list) {
-               zlog_err("Unable to alloc rp_list");
-               return;
-       }
        pim->rp_list->del = (void (*)(void *))pim_rp_info_free;
        pim->rp_list->cmp = pim_rp_list_cmp;
 
        pim->rp_table = route_table_init();
-       if (!pim->rp_table) {
-               zlog_err("Unable to alloc rp_table");
-               list_delete_and_null(&pim->rp_list);
-               return;
-       }
 
        rp_info = XCALLOC(MTYPE_PIM_RP, sizeof(*rp_info));
 
@@ -133,14 +124,6 @@ void pim_rp_init(struct pim_instance *pim)
        listnode_add(pim->rp_list, rp_info);
 
        rn = route_node_get(pim->rp_table, &rp_info->group);
-       if (!rn) {
-               zlog_err("Failure to get route node for pim->rp_table");
-               list_delete_and_null(&pim->rp_list);
-               route_table_finish(pim->rp_table);
-               XFREE(MTYPE_PIM_RP, rp_info);
-               return;
-       }
-
        rn->info = rp_info;
        if (PIM_DEBUG_TRACE)
                zlog_debug(
index 840e0d7e348b608d39e8d25bc540acedd806212e..1b11dc3f73901aabb19b60fd553904714ac4a252 100644 (file)
 
 /* PIM error codes */
 #define PIM_SUCCESS                0
-#define PIM_MALLOC_FAIL           -1
 #define PIM_GROUP_BAD_ADDRESS     -2
 #define PIM_GROUP_OVERLAP         -3
 #define PIM_GROUP_PFXLIST_OVERLAP -4
index 8032cf2ec50c1f6e612dbab581afc0684f1ce2d2..e6680ea7db4402fe6d04a187622c06b1ad0e89f0 100644 (file)
@@ -2802,15 +2802,9 @@ DEFUN_NOSH (router_rip,
        "Enable a routing process\n"
        "Routing Information Protocol (RIP)\n")
 {
-       int ret;
-
        /* If rip is not enabled before. */
        if (!rip) {
-               ret = rip_create();
-               if (ret < 0) {
-                       zlog_info("Can't create RIP");
-                       return CMD_WARNING_CONFIG_FAILED;
-               }
+               rip_create();
        }
        VTY_PUSH_CONTEXT(RIP_NODE, rip);
 
index 6cf98e85f58da359dd6a92c1ec9a49838ff24a6b..6627787fdc26b63a95cf98d677fb6d0caf6ec0d9 100644 (file)
@@ -100,11 +100,7 @@ calculate_lifc_len: /* must hold privileges to enter here */
        if (needed > lastneeded || needed < lastneeded / 2) {
                if (buf != NULL)
                        XFREE(MTYPE_TMP, buf);
-               if ((buf = XMALLOC(MTYPE_TMP, needed)) == NULL) {
-                       zlog_warn("interface_list_ioctl: malloc failed");
-                       close(sock);
-                       return -1;
-               }
+               buf = XMALLOC(MTYPE_TMP, needed);
        }
        lastneeded = needed;
 
index b24a4b68dc0d7b2e97fb3c4baa9e81013ac9e9c3..f2f89fdebe6af666f6651d2db4a2f6193e64c1ad 100644 (file)
@@ -384,8 +384,6 @@ struct label_manager_chunk *assign_label_chunk(uint8_t proto,
        }
        /* otherwise create a new one */
        lmc = XCALLOC(MTYPE_LM_CHUNK, sizeof(struct label_manager_chunk));
-       if (!lmc)
-               return NULL;
 
        if (list_isempty(lbl_mgr.lc_list))
                lmc->start = MPLS_LABEL_UNRESERVED_MIN;
index cfe208d35b0b9960b544ebc59f673cb58b4c1b81..424a11546d82d216ee46a2377535523c5db15af5 100644 (file)
@@ -550,8 +550,6 @@ static zebra_fec_t *fec_add(struct route_table *table, struct prefix *p,
 
        if (!fec) {
                fec = XCALLOC(MTYPE_FEC, sizeof(zebra_fec_t));
-               if (!fec)
-                       return NULL;
 
                rn->info = fec;
                fec->rn = rn;
@@ -1181,8 +1179,6 @@ static zebra_nhlfe_t *nhlfe_add(zebra_lsp_t *lsp, enum lsp_types_t lsp_type,
                return NULL;
 
        nhlfe = XCALLOC(MTYPE_NHLFE, sizeof(zebra_nhlfe_t));
-       if (!nhlfe)
-               return NULL;
 
        nhlfe->lsp = lsp;
        nhlfe->type = lsp_type;
index 18bd6b6cbef60d8a18ebea6a49afa50f8f8832a6..7b087b37ee6f5eef88a72deda48f3783693802d2 100644 (file)
@@ -1965,7 +1965,6 @@ static struct meta_queue *meta_queue_new(void)
        unsigned i;
 
        new = XCALLOC(MTYPE_WORK_QUEUE, sizeof(struct meta_queue));
-       assert(new);
 
        for (i = 0; i < MQ_SIZE; i++) {
                new->subq[i] = list_new();
index 0b48e87b1b7a173aca12301bc32f57a9a6e0b40f..fc17ee3491024e386784a0861a209c5441dcc43c 100644 (file)
@@ -1098,9 +1098,6 @@ static void *route_match_address_prefix_len_compile(const char *arg)
 
        prefix_len = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t));
 
-       if (!prefix_len)
-               return prefix_len;
-
        *prefix_len = tmpval;
        return prefix_len;
 }
index 4955f3f77cdb4f12f2b970694c201df8dc0e6d9a..17a25b700550183276e69917d91a5d90a9b718a2 100644 (file)
@@ -2985,10 +2985,6 @@ static zebra_vtep_t *zvni_vtep_add(zebra_vni_t *zvni, struct in_addr *vtep_ip)
        zebra_vtep_t *zvtep;
 
        zvtep = XCALLOC(MTYPE_ZVNI_VTEP, sizeof(zebra_vtep_t));
-       if (!zvtep) {
-               zlog_err("Failed to alloc VTEP entry, VNI %u", zvni->vni);
-               return NULL;
-       }
 
        zvtep->vtep_ip = *vtep_ip;