From patchwork Thu Aug 12 15:11:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 1516355 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Glqsd45Yyz9sRK for ; Fri, 13 Aug 2021 01:11:49 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 261F280C75; Thu, 12 Aug 2021 15:11:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id k39gCig3OAYk; Thu, 12 Aug 2021 15:11:43 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 6789C80C74; Thu, 12 Aug 2021 15:11:42 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 27852C001A; Thu, 12 Aug 2021 15:11:42 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4FECEC000E for ; Thu, 12 Aug 2021 15:11:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 29CE24017A for ; Thu, 12 Aug 2021 15:11:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fA7_RicuP45W for ; Thu, 12 Aug 2021 15:11:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by smtp2.osuosl.org (Postfix) with ESMTPS id 68955400E1 for ; Thu, 12 Aug 2021 15:11:40 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10074"; a="195641300" X-IronPort-AV: E=Sophos;i="5.84,316,1620716400"; d="scan'208";a="195641300" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2021 08:11:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,316,1620716400"; d="scan'208";a="676800038" Received: from silpixa00401089.ir.intel.com ([10.55.129.12]) by fmsmga005.fm.intel.com with ESMTP; 12 Aug 2021 08:11:37 -0700 From: Harry van Haaren To: dev@openvswitch.org Date: Thu, 12 Aug 2021 15:11:34 +0000 Message-Id: <20210812151134.3113110-1-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Cc: i.maximets@ovn.org, amber.kumar@intel.com Subject: [ovs-dev] [PATCH] dpif: fix memory leak of pmd_list after usage X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit fixes a memory leak when a pmd_list is retrieved from the sorted_poll_thread_list() function. Inside the function, the pmd list is allocated, but it was not freed once no longer required for the command functionality. These leaks were found by a static analysis tool. Fixes: 3d8f47bc04 ("dpif-netdev: Add command line and function pointer for miniflow extract") Fixes: abb807e27d ("dpif-netdev: Add command to switch dpif implementation.") Fixes: 3d018c3ea7 ("dpif-netdev: Add subtable lookup prio set command.") Signed-off-by: Harry van Haaren --- lib/dpif-netdev.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 03f460c7d1..99779bb402 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -960,12 +960,13 @@ dpif_netdev_subtable_lookup_set(struct unixctl_conn *conn, int argc OVS_UNUSED, } ovs_mutex_lock(&dp_netdev_mutex); + + struct dp_netdev_pmd_thread **pmd_list = NULL; SHASH_FOR_EACH (node, &dp_netdevs) { struct dp_netdev *dp = node->data; /* Get PMD threads list, required to get DPCLS instances. */ size_t n; - struct dp_netdev_pmd_thread **pmd_list; sorted_poll_thread_list(dp, &pmd_list, &n); /* take port mutex as HMAP iters over them. */ @@ -996,6 +997,7 @@ dpif_netdev_subtable_lookup_set(struct unixctl_conn *conn, int argc OVS_UNUSED, ovs_mutex_unlock(&dp->port_mutex); } ovs_mutex_unlock(&dp_netdev_mutex); + free(pmd_list); struct ds reply = DS_EMPTY_INITIALIZER; ds_put_format(&reply, @@ -1013,10 +1015,10 @@ dpif_netdev_impl_get(struct unixctl_conn *conn, int argc OVS_UNUSED, { struct ds reply = DS_EMPTY_INITIALIZER; struct shash_node *node; + struct dp_netdev_pmd_thread **pmd_list = NULL; ovs_mutex_lock(&dp_netdev_mutex); SHASH_FOR_EACH (node, &dp_netdevs) { - struct dp_netdev_pmd_thread **pmd_list; struct dp_netdev *dp = node->data; size_t n; @@ -1026,6 +1028,8 @@ dpif_netdev_impl_get(struct unixctl_conn *conn, int argc OVS_UNUSED, dp_netdev_impl_get(&reply, pmd_list, n); } ovs_mutex_unlock(&dp_netdev_mutex); + free(pmd_list); + unixctl_command_reply(conn, ds_cstr(&reply)); ds_destroy(&reply); } @@ -1058,12 +1062,12 @@ dpif_netdev_impl_set(struct unixctl_conn *conn, int argc OVS_UNUSED, return; } + struct dp_netdev_pmd_thread **pmd_list = NULL; SHASH_FOR_EACH (node, &dp_netdevs) { struct dp_netdev *dp = node->data; /* Get PMD threads list, required to get DPCLS instances. */ size_t n; - struct dp_netdev_pmd_thread **pmd_list; sorted_poll_thread_list(dp, &pmd_list, &n); for (size_t i = 0; i < n; i++) { @@ -1080,6 +1084,7 @@ dpif_netdev_impl_set(struct unixctl_conn *conn, int argc OVS_UNUSED, }; } ovs_mutex_unlock(&dp_netdev_mutex); + free(pmd_list); /* Reply with success to command. */ struct ds reply = DS_EMPTY_INITIALIZER; @@ -1099,8 +1104,8 @@ dpif_miniflow_extract_impl_get(struct unixctl_conn *conn, int argc OVS_UNUSED, struct shash_node *node; ovs_mutex_lock(&dp_netdev_mutex); + struct dp_netdev_pmd_thread **pmd_list = NULL; SHASH_FOR_EACH (node, &dp_netdevs) { - struct dp_netdev_pmd_thread **pmd_list; struct dp_netdev *dp = node->data; size_t n; @@ -1110,6 +1115,8 @@ dpif_miniflow_extract_impl_get(struct unixctl_conn *conn, int argc OVS_UNUSED, dp_mfex_impl_get(&reply, pmd_list, n); } ovs_mutex_unlock(&dp_netdev_mutex); + free(pmd_list); + unixctl_command_reply(conn, ds_cstr(&reply)); ds_destroy(&reply); } @@ -1243,8 +1250,8 @@ dpif_miniflow_extract_impl_set(struct unixctl_conn *conn, int argc, */ ovs_mutex_lock(&dp_netdev_mutex); + struct dp_netdev_pmd_thread **pmd_list = NULL; SHASH_FOR_EACH (node, &dp_netdevs) { - struct dp_netdev_pmd_thread **pmd_list; struct dp_netdev *dp = node->data; size_t n; @@ -1269,6 +1276,7 @@ dpif_miniflow_extract_impl_set(struct unixctl_conn *conn, int argc, } ovs_mutex_unlock(&dp_netdev_mutex); + free(pmd_list); /* If PMD thread was specified, but it wasn't found, return error. */ if (pmd_thread_to_change != NON_PMD_CORE_ID && !pmd_thread_update_done) {