From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 74C5811A4 for ; Mon, 10 Sep 2018 15:47:01 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2018 06:47:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,355,1531810800"; d="scan'208";a="84638284" Received: from ziyeyang-mobl.ccr.corp.intel.com (HELO localhost.localdomain) ([10.254.213.36]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2018 06:46:59 -0700 From: Ziye Yang To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, Ziye Yang Date: Mon, 10 Sep 2018 21:46:50 +0800 Message-Id: <1536587210-35122-1-git-send-email-ziye.yang@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1536125954-46632-1-git-send-email-ziye.yang@intel.com> References: <1536125954-46632-1-git-send-email-ziye.yang@intel.com> Subject: [dpdk-dev] [PATCH v6] linuxapp, eal: Fix the memory leak issue of logid 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: Mon, 10 Sep 2018 13:47:01 -0000 From: Ziye Yang This patch is used to fix the memory leak issue of logid. We use the ASAN test in SPDK when intergrating DPDK and find this memory leak issue. By the way, we also fix several missed function call of rte_atomic32_clear. Signed-off-by: Ziye Yang --- lib/librte_eal/linuxapp/eal/eal.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index e59ac65..a1b218a 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -793,7 +793,8 @@ static void rte_eal_init_alert(const char *msg) int i, fctret, ret; pthread_t thread_id; static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0); - const char *logid; + const char *p; + static char logid[PATH_MAX]; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; char thread_name[RTE_MAX_THREAD_NAME_LEN]; @@ -810,9 +811,8 @@ static void rte_eal_init_alert(const char *msg) return -1; } - logid = strrchr(argv[0], '/'); - logid = strdup(logid ? logid + 1: argv[0]); - + p = strrchr(argv[0], '/'); + snprintf(logid, sizeof(logid), "%s", (p ? p + 1: argv[0])); thread_id = pthread_self(); eal_reset_internal_config(&internal_config); @@ -823,6 +823,7 @@ static void rte_eal_init_alert(const char *msg) if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); rte_errno = ENOTSUP; + rte_atomic32_clear(&run_once); return -1; } @@ -851,6 +852,7 @@ static void rte_eal_init_alert(const char *msg) if (rte_eal_intr_init() < 0) { rte_eal_init_alert("Cannot init interrupt-handling thread\n"); + rte_atomic32_clear(&run_once); return -1; } @@ -861,6 +863,7 @@ static void rte_eal_init_alert(const char *msg) rte_eal_init_alert("failed to init mp channel\n"); if (rte_eal_process_type() == RTE_PROC_PRIMARY) { rte_errno = EFAULT; + rte_atomic32_clear(&run_once); return -1; } } -- 1.9.3