From patchwork Sat May 23 10:52:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunjian Wang X-Patchwork-Id: 70548 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A31C6A04A3; Sat, 23 May 2020 12:52:35 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E62231D44D; Sat, 23 May 2020 12:52:34 +0200 (CEST) Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) by dpdk.org (Postfix) with ESMTP id 44DE81BF85; Sat, 23 May 2020 12:52:33 +0200 (CEST) Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 4BC918EEECBFBF71CDA9; Sat, 23 May 2020 18:52:29 +0800 (CST) Received: from localhost (10.173.251.152) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Sat, 23 May 2020 18:52:22 +0800 From: wangyunjian To: CC: , , Yunjian Wang , Date: Sat, 23 May 2020 18:52:21 +0800 Message-ID: <1590231141-30684-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 X-Originating-IP: [10.173.251.152] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH] eal: fix memory leak in uevent parse and process X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Yunjian Wang When the memory for uevent.devname is allocated in dev_uev_parse(). It is not freed when parse the subsystem layer fails in dev_uev_parse(). And Before return, it is also not freed in dev_uev_handler(). These cause a memory leak. Fixes: 0d0f478d0483 ("eal/linux: add uevent parse and process") Cc: stable@dpdk.org Signed-off-by: Yunjian Wang Reviewed-by: David Marchand --- lib/librte_eal/linux/eal_dev.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/linux/eal_dev.c b/lib/librte_eal/linux/eal_dev.c index 83c9cd660..3a2bf8514 100644 --- a/lib/librte_eal/linux/eal_dev.c +++ b/lib/librte_eal/linux/eal_dev.c @@ -189,7 +189,7 @@ dev_uev_parse(const char *buf, struct rte_dev_event *event, int length) else if (!strncmp(subsystem, "vfio", 4)) event->subsystem = EAL_DEV_EVENT_SUBSYSTEM_VFIO; else - return -1; + goto out; /* parse the action type */ if (!strncmp(action, "add", 3)) @@ -197,8 +197,12 @@ dev_uev_parse(const char *buf, struct rte_dev_event *event, int length) else if (!strncmp(action, "remove", 6)) event->type = RTE_DEV_EVENT_REMOVE; else - return -1; + goto out; return 0; +out: + if (event->devname) + free(event->devname); + return -1; } static void @@ -277,12 +281,14 @@ dev_uev_handler(__rte_unused void *param) rte_spinlock_unlock(&failure_handle_lock); } rte_dev_event_callback_process(uevent.devname, uevent.type); + free(uevent.devname); } return; failure_handle_err: rte_spinlock_unlock(&failure_handle_lock); + free(uevent.devname); } int