DPDK patches and discussions
 help / color / mirror / Atom feed
From: Weiguo Li <liwg06@foxmail.com>
To: dev@dpdk.org
Cc: adypodoman@gmail.com, xiaoyun.li@intel.com,
	tianfei.zhang@intel.com, bruce.richardson@intel.com,
	ivan.malov@oktetlabs.ru, jgrajcia@cisco.com, hkalra@marvell.com,
	ying.a.wang@intel.com, ting.xu@intel.com, simei.su@intel.com,
	qiming.yang@intel.com, motih@mellanox.com,
	shreyansh.jain@nxp.com, skoteshwar@marvell.com,
	stephen@networkplumber.org, kalesh-anakkur.purayil@broadcom.com,
	somnath.kotur@broadcom.com, declan.doherty@intel.com,
	gakhil@marvell.com, nicolas.chautru@intel.com
Subject: [PATCH 15/20] net/memif: fix some memory leaks in error handlings
Date: Wed, 23 Feb 2022 02:18:13 +0800	[thread overview]
Message-ID: <tencent_A84207E75B69E45F043AA68F07ED5426C205@qq.com> (raw)
In-Reply-To: <cover.1645551559.git.liwg06@foxmail.com>

1) When the validate to 'reply->num_fds' fails, memif_region 'r' is not
   released, we can move the validation ahead of the memory allocation to
   avoid this memory leak.
2) In some error handlings, functions were returned without releasing the
   memory. Fix them altogether in this patch.

Fixes: c41a04958b09 ("net/memif: support multi-process")
Fixes: 43b815d88188 ("net/memif: support zero-copy slave")
Fixes: d61138d4f0e2 ("drivers: remove direct access to interrupt handle")

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
---
 drivers/net/memif/rte_eth_memif.c | 32 +++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/drivers/net/memif/rte_eth_memif.c b/drivers/net/memif/rte_eth_memif.c
index 587ad45576..ddbdeb6241 100644
--- a/drivers/net/memif/rte_eth_memif.c
+++ b/drivers/net/memif/rte_eth_memif.c
@@ -158,6 +158,11 @@ memif_mp_request_regions(struct rte_eth_dev *dev)
 		reply_param = (struct mp_region_msg *)reply->param;
 
 		if (reply_param->size > 0) {
+			if (reply->num_fds < 1) {
+				MIF_LOG(ERR, "Missing file descriptor.");
+				free(reply);
+				return -1;
+			}
 			r = rte_zmalloc("region", sizeof(struct memif_region), 0);
 			if (r == NULL) {
 				MIF_LOG(ERR, "Failed to alloc memif region.");
@@ -165,11 +170,6 @@ memif_mp_request_regions(struct rte_eth_dev *dev)
 				return -ENOMEM;
 			}
 			r->region_size = reply_param->size;
-			if (reply->num_fds < 1) {
-				MIF_LOG(ERR, "Missing file descriptor.");
-				free(reply);
-				return -1;
-			}
 			r->fd = reply->fds[0];
 			r->addr = NULL;
 
@@ -913,8 +913,10 @@ memif_region_init_zc(const struct rte_memseg_list *msl, const struct rte_memseg
 		r->addr = msl->base_va;
 		r->region_size = ms->len;
 		r->fd = rte_memseg_get_fd(ms);
-		if (r->fd < 0)
+		if (r->fd < 0) {
+			rte_free(r);
 			return -1;
+		}
 		r->pkt_buffer_offset = 0;
 
 		proc_private->regions[proc_private->regions_num - 1] = r;
@@ -1328,6 +1330,7 @@ memif_tx_queue_setup(struct rte_eth_dev *dev,
 	mq->intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_SHARED);
 	if (mq->intr_handle == NULL) {
 		MIF_LOG(ERR, "Failed to allocate intr handle");
+		rte_free(mq);
 		return -ENOMEM;
 	}
 
@@ -1336,11 +1339,15 @@ memif_tx_queue_setup(struct rte_eth_dev *dev,
 	mq->n_pkts = 0;
 	mq->n_bytes = 0;
 
-	if (rte_intr_fd_set(mq->intr_handle, -1))
+	if (rte_intr_fd_set(mq->intr_handle, -1)) {
+		rte_free(mq);
 		return -rte_errno;
+	}
 
-	if (rte_intr_type_set(mq->intr_handle, RTE_INTR_HANDLE_EXT))
+	if (rte_intr_type_set(mq->intr_handle, RTE_INTR_HANDLE_EXT)) {
+		rte_free(mq);
 		return -rte_errno;
+	}
 
 	mq->in_port = dev->data->port_id;
 	dev->data->tx_queues[qid] = mq;
@@ -1369,6 +1376,7 @@ memif_rx_queue_setup(struct rte_eth_dev *dev,
 	mq->intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_SHARED);
 	if (mq->intr_handle == NULL) {
 		MIF_LOG(ERR, "Failed to allocate intr handle");
+		rte_free(mq);
 		return -ENOMEM;
 	}
 
@@ -1376,11 +1384,15 @@ memif_rx_queue_setup(struct rte_eth_dev *dev,
 	mq->n_pkts = 0;
 	mq->n_bytes = 0;
 
-	if (rte_intr_fd_set(mq->intr_handle, -1))
+	if (rte_intr_fd_set(mq->intr_handle, -1)) {
+		rte_free(mq);
 		return -rte_errno;
+	}
 
-	if (rte_intr_type_set(mq->intr_handle, RTE_INTR_HANDLE_EXT))
+	if (rte_intr_type_set(mq->intr_handle, RTE_INTR_HANDLE_EXT)) {
+		rte_free(mq);
 		return -rte_errno;
+	}
 
 	mq->mempool = mb_pool;
 	mq->in_port = dev->data->port_id;
-- 
2.25.1


  parent reply	other threads:[~2022-02-22 18:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1645551559.git.liwg06@foxmail.com>
2022-02-22 18:17 ` [PATCH 01/20] baseband/acc100: fix a memory leak in acc100 queue setup Weiguo Li
2022-02-23 17:42   ` Chautru, Nicolas
2022-06-24 20:45   ` David Marchand
2022-02-22 18:18 ` [PATCH 02/20] common/dpaax: fix a memory leak in iterate dir Weiguo Li
2022-02-22 18:18 ` [PATCH 03/20] crypto/dpaa2_sec: fix memory leaks in error handlings Weiguo Li
2022-06-24 20:46   ` David Marchand
2022-02-22 18:18 ` [PATCH 04/20] crypto/qat: fix a memory leak when set encrypt key fail Weiguo Li
2022-06-24 20:49   ` David Marchand
2022-02-22 18:18 ` [PATCH 05/20] net/bnxt: fix a memory leak in error handling Weiguo Li
2022-02-22 18:18 ` [PATCH 06/20] net/bnxt: fix 'ctx' memory leak when new malloc fail Weiguo Li
2022-02-22 18:18 ` [PATCH 07/20] net/bnx2x: add clean up for 'rxq' to avoid a memory leak Weiguo Li
2022-02-22 18:18 ` [PATCH 08/20] net/cnxk: free 'node' memory when node add fail Weiguo Li
2022-04-07  9:02   ` Nithin Kumar Dabilpuram
2022-02-22 18:18 ` [PATCH 09/20] net/dpaa: fix a memory leak when validation fail Weiguo Li
2022-02-22 18:18 ` [PATCH 10/20] net/failsafe: fix a memory leak in error handling Weiguo Li
2022-02-22 18:18 ` [PATCH 11/20] net/iavf: " Weiguo Li
2022-02-22 18:18 ` [PATCH 12/20] net/ice: goto clean up lable to avoid memory leak Weiguo Li
2022-02-22 18:18 ` [PATCH 13/20] net/ice: fix memory leaks in error handlings Weiguo Li
2022-06-02  8:04   ` David Marchand
2022-02-22 18:18 ` [PATCH 14/20] net/ice: avoid fix memory leaks in register parser Weiguo Li
2022-02-22 18:18 ` Weiguo Li [this message]
2022-02-22 18:18 ` [PATCH 16/20] net/sfc: fix a memory leak in error handling Weiguo Li
2022-03-03  7:39   ` Andrew Rybchenko
2022-02-22 18:18 ` [PATCH 17/20] net/vmxnet3: fix memory leaks in error handlings Weiguo Li
2022-02-22 18:18 ` [PATCH 18/20] raw/ifpga/base: " Weiguo Li
2022-02-22 18:28 ` [PATCH 19/20] raw/ntb: fix some " Weiguo Li
2022-02-22 18:28 ` [PATCH 20/20] regex/mlx5: fix a memory leak in error handling Weiguo Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_A84207E75B69E45F043AA68F07ED5426C205@qq.com \
    --to=liwg06@foxmail.com \
    --cc=adypodoman@gmail.com \
    --cc=bruce.richardson@intel.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=hkalra@marvell.com \
    --cc=ivan.malov@oktetlabs.ru \
    --cc=jgrajcia@cisco.com \
    --cc=kalesh-anakkur.purayil@broadcom.com \
    --cc=motih@mellanox.com \
    --cc=nicolas.chautru@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=shreyansh.jain@nxp.com \
    --cc=simei.su@intel.com \
    --cc=skoteshwar@marvell.com \
    --cc=somnath.kotur@broadcom.com \
    --cc=stephen@networkplumber.org \
    --cc=tianfei.zhang@intel.com \
    --cc=ting.xu@intel.com \
    --cc=xiaoyun.li@intel.com \
    --cc=ying.a.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).