From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7C8E6A034E; Tue, 22 Feb 2022 19:20:08 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 19D044115F; Tue, 22 Feb 2022 19:19:26 +0100 (CET) Received: from out203-205-221-236.mail.qq.com (out203-205-221-236.mail.qq.com [203.205.221.236]) by mails.dpdk.org (Postfix) with ESMTP id AB5314120A for ; Tue, 22 Feb 2022 19:19:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1645553961; bh=NFCZfcozpxnV9v1aVmL+ENEiEi9KciNkzT9FpOeGO1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kkW/Lk98YvO7hnr55sFCE9Ck1S+kAY1BSKXCmWF+XzN5DudpKHXhb5zcSnE1igdKp Ot7niSKxx9z9k8gwCsV68auKyun0H2wLl5PKIGeKCFysrm6Rvx/hyzt0GrVwMncWlY pN0vu6hXE+n67YAg45UCxf4ES+Ap1vOtnLRwXMRw= Received: from localhost.localdomain ([111.193.130.237]) by newxmesmtplogicsvrszc6.qq.com (NewEsmtp) with SMTP id 49223207; Wed, 23 Feb 2022 02:18:18 +0800 X-QQ-mid: xmsmtpt1645553957tb22hr35w Message-ID: X-QQ-XMAILINFO: Nkm5Fff6p/24238ChlWPL2oDwXO0XOGjW0u0GnhqP0TMBvLgbjS1Vu2K0HkxlK ieSBeGUO/FoTfxp9ZmmgdhGV+4qtQjWmFArvWaCOayk0+BREIbxOrvIdfpt65b83USBAfrmzEKhG 0fYV4O198EoOwxisww4/eNwluD8ImyYkvYhMPHXqMr/EmJ9aj3KTWhPfl/p8cUMMYFwVf5kJIaKJ ER4RawpSkZo1hlXO0G2OtWdkXEkT6Y7JITw1a4pTnPU191woNJXc78Lst5Kj09/WkiIgF5TcOW4n tPfDx83KGknUYcTaS8xHeqjgmcohZS1jxV3JtzgC/Cb2A05BXDKVsdd9SLdeqreHgA8kGHeG/v9I lDgSsNnTPgVLQr5He8ijTQj8R7eLMw4uTqFIABOOD+BBeXfgVN0JnMbk6R39tLDHzRfgTeIZ1py8 /rQh4e0CS2HgXTd1/nQ0I1ykmQBZyi21EDEi2zTJSJgubpyJhDn4xWYrLEIwcHMFH6WXFnOiy90G ib4H2wsxfBGeisrV3AsqZffx8PIvM/Dl3zH8AmYNBP1D9oETi6ZUd0YR8W4E604xzzOUM/0PQ93E o+ytHOs++dEO91b4jXZh74TYdNPJo8GX1jB9JhUbx4e6ce8jN0dyRMFD3ZE7Ou7DWB8pwKsUTzqY W2SD4QG7ni+JRfSQdFSXyga/uwDH8ZmnEkwyU7cnEUTdcyVEPsPU04t9tVFVBqsBkV3cRcL0+J/Z 0zOvZBkFT6XFYGdypwsGeGdar408orss2k0OKyyKLzZJLvqA2KWh05drCOjoRbZcAxvIvO+Zm6R+ NNqQLWfwZVH/GYCPD2j1M+0vL4iY0Fs+5QJlubBfo19JN+OVqSS9eoLo9dz/fUt9ojUmHkNOZRKM OHx4ZGG2TAOSnsv8ei5r6VyEQ9/2VtPg== From: Weiguo Li 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 X-OQ-MSGID: <49e2a75f244b377045bf86e6dc4784507c3c273c.1645551559.git.liwg06@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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