From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 86B991559 for ; Wed, 5 Sep 2018 06:57:18 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Sep 2018 21:57:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,332,1531810800"; d="scan'208";a="259934203" Received: from ziyeyang-mobl.ccr.corp.intel.com (HELO localhost.localdomain.localdomain) ([10.67.64.110]) by fmsmga005.fm.intel.com with ESMTP; 04 Sep 2018 21:56:32 -0700 From: Ziye Yang To: dev@dpdk.org Cc: Ziye Yang Date: Wed, 5 Sep 2018 12:56:30 +0800 Message-Id: <1536123390-12762-1-git-send-email-ziye.yang@intel.com> X-Mailer: git-send-email 1.9.3 Subject: [dpdk-dev] [PATCH v3] 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: Wed, 05 Sep 2018 04:57:19 -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. Signed-off-by: Ziye Yang --- lib/librte_eal/linuxapp/eal/eal.c | 13 ++++++++++++- lib/librte_eal/linuxapp/eal/eal_log.c | 12 +++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index e59ac65..0ddd660 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -793,7 +793,7 @@ 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; + char *logid; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; char thread_name[RTE_MAX_THREAD_NAME_LEN]; @@ -812,6 +812,12 @@ static void rte_eal_init_alert(const char *msg) logid = strrchr(argv[0], '/'); logid = strdup(logid ? logid + 1: argv[0]); + if (!logid) { + rte_eal_init_alert("Cannot allocate memory for logid\n"); + rte_errno = ENOMEM; + rte_atomic32_clear(&run_once); + return -1; + } thread_id = pthread_self(); @@ -823,6 +829,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; + free(logid); return -1; } @@ -831,6 +838,7 @@ static void rte_eal_init_alert(const char *msg) rte_eal_init_alert("Invalid 'command line' arguments."); rte_errno = EINVAL; rte_atomic32_clear(&run_once); + free(logid); return -1; } @@ -844,6 +852,7 @@ static void rte_eal_init_alert(const char *msg) if (eal_option_device_parse()) { rte_errno = ENODEV; rte_atomic32_clear(&run_once); + free(logid); return -1; } @@ -851,8 +860,10 @@ 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"); + free(logid); return -1; } + free(logid); /* Put mp channel init before bus scan so that we can init the vdev * bus through mp channel in the secondary process before the bus scan. diff --git a/lib/librte_eal/linuxapp/eal/eal_log.c b/lib/librte_eal/linuxapp/eal/eal_log.c index 9d02ddd..9bd8566 100644 --- a/lib/librte_eal/linuxapp/eal/eal_log.c +++ b/lib/librte_eal/linuxapp/eal/eal_log.c @@ -19,6 +19,9 @@ #include "eal_private.h" +#define DEFAULT_LOG_ID_LEN 128 +char g_logid[DEFAULT_LOG_ID_LEN]; + /* * default log function */ @@ -49,12 +52,19 @@ rte_eal_log_init(const char *id, int facility) { FILE *log_stream; + int str_len; log_stream = fopencookie(NULL, "w+", console_log_func); if (log_stream == NULL) return -1; - openlog(id, LOG_NDELAY | LOG_PID, facility); + str_len = strlen(id); + if(str_len >= DEFAULT_LOG_ID_LEN) { + return -1; + } + + strncpy(g_logid, id, str_len); + openlog(g_logid, LOG_NDELAY | LOG_PID, facility); eal_log_set_default(log_stream); -- 1.9.3