mem: fix possible integer overflow
[dpdk.git] / lib / librte_lpm / rte_lpm6.c
index eded772..32fdba0 100644 (file)
@@ -182,8 +182,11 @@ rte_lpm6_create(const char *name, int socket_id,
                if (strncmp(name, lpm->name, RTE_LPM6_NAMESIZE) == 0)
                        break;
        }
-       if (te != NULL)
+       lpm = NULL;
+       if (te != NULL) {
+               rte_errno = EEXIST;
                goto exit;
+       }
 
        /* allocate tailq entry */
        te = rte_zmalloc("LPM6_TAILQ_ENTRY", sizeof(*te), 0);
@@ -206,8 +209,9 @@ rte_lpm6_create(const char *name, int socket_id,
                        (size_t)rules_size, RTE_CACHE_LINE_SIZE, socket_id);
 
        if (lpm->rules_tbl == NULL) {
-               RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
+               RTE_LOG(ERR, LPM, "LPM rules_tbl allocation failed\n");
                rte_free(lpm);
+               lpm = NULL;
                rte_free(te);
                goto exit;
        }
@@ -597,7 +601,7 @@ int
 rte_lpm6_lookup(const struct rte_lpm6 *lpm, uint8_t *ip, uint8_t *next_hop)
 {
        const struct rte_lpm6_tbl_entry *tbl;
-       const struct rte_lpm6_tbl_entry *tbl_next;
+       const struct rte_lpm6_tbl_entry *tbl_next = NULL;
        int status;
        uint8_t first_byte;
        uint32_t tbl24_index;
@@ -632,7 +636,7 @@ rte_lpm6_lookup_bulk_func(const struct rte_lpm6 *lpm,
 {
        unsigned i;
        const struct rte_lpm6_tbl_entry *tbl;
-       const struct rte_lpm6_tbl_entry *tbl_next;
+       const struct rte_lpm6_tbl_entry *tbl_next = NULL;
        uint32_t tbl24_index;
        uint8_t first_byte, next_hop;
        int status;