net/i40e: fix memory leak
authorYong Wang <wang.yong19@zte.com.cn>
Thu, 25 Jan 2018 09:01:04 +0000 (04:01 -0500)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 29 Jan 2018 09:04:28 +0000 (10:04 +0100)
There are several func calls to rte_zmalloc() which don't have null
pointer check on the return value. And before return, the memory
is not freed. It fixes by adding null pointer check and rte_free().

Fixes: 078259773da9 ("net/i40e: store ethertype filter")
Fixes: 425c3325f0b0 ("net/i40e: store tunnel filter")
Fixes: c50474f31efe ("net/i40e: support tunnel filter to VF")
Fixes: 5c53c82c8174 ("net/i40e: store flow director filter")
Cc: stable@dpdk.org
Signed-off-by: Yong Wang <wang.yong19@zte.com.cn>
Acked-by: Beilei Xing <beilei.xing@intel.com>
drivers/net/i40e/i40e_ethdev.c
drivers/net/i40e/i40e_fdir.c

index c4df65d..277c1a8 100644 (file)
@@ -7188,11 +7188,13 @@ i40e_dev_tunnel_filter_set(struct i40e_pf *pf,
        node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
        if (add && node) {
                PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
+               rte_free(cld_filter);
                return -EINVAL;
        }
 
        if (!add && !node) {
                PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
+               rte_free(cld_filter);
                return -EINVAL;
        }
 
@@ -7201,16 +7203,26 @@ i40e_dev_tunnel_filter_set(struct i40e_pf *pf,
                                        vsi->seid, &cld_filter->element, 1);
                if (ret < 0) {
                        PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
+                       rte_free(cld_filter);
                        return -ENOTSUP;
                }
                tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
+               if (tunnel == NULL) {
+                       PMD_DRV_LOG(ERR, "Failed to alloc memory.");
+                       rte_free(cld_filter);
+                       return -ENOMEM;
+               }
+
                rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
                ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
+               if (ret < 0)
+                       rte_free(tunnel);
        } else {
                ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
                                                   &cld_filter->element, 1);
                if (ret < 0) {
                        PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
+                       rte_free(cld_filter);
                        return -ENOTSUP;
                }
                ret = i40e_sw_tunnel_filter_del(pf, &node->input);
@@ -7639,6 +7651,7 @@ i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
        else {
                if (tunnel_filter->vf_id >= pf->vf_num) {
                        PMD_DRV_LOG(ERR, "Invalid argument.");
+                       rte_free(cld_filter);
                        return -EINVAL;
                }
                vf = &pf->vfs[tunnel_filter->vf_id];
@@ -7653,11 +7666,13 @@ i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
        node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
        if (add && node) {
                PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
+               rte_free(cld_filter);
                return -EINVAL;
        }
 
        if (!add && !node) {
                PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
+               rte_free(cld_filter);
                return -EINVAL;
        }
 
@@ -7670,11 +7685,20 @@ i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
                                        vsi->seid, &cld_filter->element, 1);
                if (ret < 0) {
                        PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
+                       rte_free(cld_filter);
                        return -ENOTSUP;
                }
                tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
+               if (tunnel == NULL) {
+                       PMD_DRV_LOG(ERR, "Failed to alloc memory.");
+                       rte_free(cld_filter);
+                       return -ENOMEM;
+               }
+
                rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
                ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
+               if (ret < 0)
+                       rte_free(tunnel);
        } else {
                if (big_buffer)
                        ret = i40e_aq_remove_cloud_filters_big_buffer(
@@ -7684,6 +7708,7 @@ i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
                                                   &cld_filter->element, 1);
                if (ret < 0) {
                        PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
+                       rte_free(cld_filter);
                        return -ENOTSUP;
                }
                ret = i40e_sw_tunnel_filter_del(pf, &node->input);
@@ -9295,9 +9320,16 @@ i40e_ethertype_filter_set(struct i40e_pf *pf,
        if (add) {
                ethertype_filter = rte_zmalloc("ethertype_filter",
                                       sizeof(*ethertype_filter), 0);
+               if (ethertype_filter == NULL) {
+                       PMD_DRV_LOG(ERR, "Failed to alloc memory.");
+                       return -ENOMEM;
+               }
+
                rte_memcpy(ethertype_filter, &check_filter,
                           sizeof(check_filter));
                ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
+               if (ret < 0)
+                       rte_free(ethertype_filter);
        } else {
                ret = i40e_sw_ethertype_filter_del(pf, &node->input);
        }
index a4320b1..c392dc4 100644 (file)
@@ -1595,8 +1595,15 @@ i40e_flow_add_del_fdir_filter(struct rte_eth_dev *dev,
        if (add) {
                fdir_filter = rte_zmalloc("fdir_filter",
                                          sizeof(*fdir_filter), 0);
+               if (fdir_filter == NULL) {
+                       PMD_DRV_LOG(ERR, "Failed to alloc memory.");
+                       return -ENOMEM;
+               }
+
                rte_memcpy(fdir_filter, &check_filter, sizeof(check_filter));
                ret = i40e_sw_fdir_filter_insert(pf, fdir_filter);
+               if (ret < 0)
+                       rte_free(fdir_filter);
        } else {
                ret = i40e_sw_fdir_filter_del(pf, &node->fdir.input);
        }