From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id EA01E137C for ; Wed, 1 May 2019 21:01:41 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 May 2019 12:01:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,418,1549958400"; d="scan'208";a="166779944" Received: from txasoft-yocto.an.intel.com ([10.123.72.192]) by fmsmga004.fm.intel.com with ESMTP; 01 May 2019 12:01:40 -0700 From: Erik Gabriel Carrillo To: rsanford@akamai.com, thomas@monjalon.net Cc: dev@dpdk.org Date: Wed, 1 May 2019 14:00:17 -0500 Message-Id: <1556737217-24338-1-git-send-email-erik.g.carrillo@intel.com> X-Mailer: git-send-email 1.7.10 Subject: [dpdk-dev] [PATCH] timer: fix resource leak in finalize 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: , X-List-Received-Date: Wed, 01 May 2019 19:01:42 -0000 The finalize function should free the memzone created in the init function, rather than freeing the allocation the memzone references, otherwise a memzone descriptor can be leaked. Fixes: c0749f7096c7 ("timer: allow management in shared memory") Signed-off-by: Erik Gabriel Carrillo --- lib/librte_timer/rte_timer.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c index eb46009..fb7a87e 100644 --- a/lib/librte_timer/rte_timer.c +++ b/lib/librte_timer/rte_timer.c @@ -60,6 +60,7 @@ struct rte_timer_data { }; #define RTE_MAX_DATA_ELS 64 +static const struct rte_memzone *rte_timer_data_mz; static struct rte_timer_data *rte_timer_data_arr; static const uint32_t default_data_id; static uint32_t rte_timer_subsystem_initialized; @@ -164,6 +165,7 @@ rte_timer_subsystem_init_v1905(void) if (mz == NULL) return -EEXIST; + rte_timer_data_mz = mz; rte_timer_data_arr = mz->addr; rte_timer_data_arr[default_data_id].internal_flags |= @@ -180,6 +182,7 @@ rte_timer_subsystem_init_v1905(void) if (mz == NULL) return -ENOMEM; + rte_timer_data_mz = mz; rte_timer_data_arr = mz->addr; for (i = 0; i < RTE_MAX_DATA_ELS; i++) { @@ -205,8 +208,13 @@ BIND_DEFAULT_SYMBOL(rte_timer_subsystem_init, _v1905, 19.05); void __rte_experimental rte_timer_subsystem_finalize(void) { - if (rte_timer_data_arr) - rte_free(rte_timer_data_arr); + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return; + + if (!rte_timer_subsystem_initialized) + return; + + rte_memzone_free(rte_timer_data_mz); rte_timer_subsystem_initialized = 0; } -- 2.6.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id B6782A0AC5 for ; Wed, 1 May 2019 21:01:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 916A21C0B; Wed, 1 May 2019 21:01:43 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id EA01E137C for ; Wed, 1 May 2019 21:01:41 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 May 2019 12:01:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,418,1549958400"; d="scan'208";a="166779944" Received: from txasoft-yocto.an.intel.com ([10.123.72.192]) by fmsmga004.fm.intel.com with ESMTP; 01 May 2019 12:01:40 -0700 From: Erik Gabriel Carrillo To: rsanford@akamai.com, thomas@monjalon.net Cc: dev@dpdk.org Date: Wed, 1 May 2019 14:00:17 -0500 Message-Id: <1556737217-24338-1-git-send-email-erik.g.carrillo@intel.com> X-Mailer: git-send-email 1.7.10 Subject: [dpdk-dev] [PATCH] timer: fix resource leak in finalize 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" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190501190017.Mp78xqK4l9hnvIzDLYuBKNCXWgIr_2tI2Dx82n0Koc0@z> The finalize function should free the memzone created in the init function, rather than freeing the allocation the memzone references, otherwise a memzone descriptor can be leaked. Fixes: c0749f7096c7 ("timer: allow management in shared memory") Signed-off-by: Erik Gabriel Carrillo --- lib/librte_timer/rte_timer.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c index eb46009..fb7a87e 100644 --- a/lib/librte_timer/rte_timer.c +++ b/lib/librte_timer/rte_timer.c @@ -60,6 +60,7 @@ struct rte_timer_data { }; #define RTE_MAX_DATA_ELS 64 +static const struct rte_memzone *rte_timer_data_mz; static struct rte_timer_data *rte_timer_data_arr; static const uint32_t default_data_id; static uint32_t rte_timer_subsystem_initialized; @@ -164,6 +165,7 @@ rte_timer_subsystem_init_v1905(void) if (mz == NULL) return -EEXIST; + rte_timer_data_mz = mz; rte_timer_data_arr = mz->addr; rte_timer_data_arr[default_data_id].internal_flags |= @@ -180,6 +182,7 @@ rte_timer_subsystem_init_v1905(void) if (mz == NULL) return -ENOMEM; + rte_timer_data_mz = mz; rte_timer_data_arr = mz->addr; for (i = 0; i < RTE_MAX_DATA_ELS; i++) { @@ -205,8 +208,13 @@ BIND_DEFAULT_SYMBOL(rte_timer_subsystem_init, _v1905, 19.05); void __rte_experimental rte_timer_subsystem_finalize(void) { - if (rte_timer_data_arr) - rte_free(rte_timer_data_arr); + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return; + + if (!rte_timer_subsystem_initialized) + return; + + rte_memzone_free(rte_timer_data_mz); rte_timer_subsystem_initialized = 0; } -- 2.6.4