From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 3262711A4 for ; Mon, 10 Sep 2018 14:28:48 +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 fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2018 05:28:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,355,1531810800"; d="scan'208";a="261323246" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga005.fm.intel.com with ESMTP; 10 Sep 2018 05:23:40 -0700 Received: from FMSMSX110.amr.corp.intel.com (10.18.116.10) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 10 Sep 2018 05:23:40 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx110.amr.corp.intel.com (10.18.116.10) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 10 Sep 2018 05:23:40 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.226]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.16]) with mapi id 14.03.0319.002; Mon, 10 Sep 2018 20:23:38 +0800 From: "Yang, Ziye" To: "Ananyev, Konstantin" , "dev@dpdk.org" CC: Ziye Yang Thread-Topic: [dpdk-dev] [PATCH v5] linuxapp, eal: Fix the memory leak issue of logid Thread-Index: AQHURNr7E3rktHeMwUq0FIlXiCdNO6Tk2RhAgASXvoCAAASrcIAAAsgQ Date: Mon, 10 Sep 2018 12:23:37 +0000 Message-ID: References: <1536125954-46632-1-git-send-email-ziye.yang@intel.com> <2601191342CEEE43887BDE71AB977258EA953A94@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB977258EA953AD7@irsmsx105.ger.corp.intel.com> In-Reply-To: <2601191342CEEE43887BDE71AB977258EA953AD7@irsmsx105.ger.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYzJhNWM3MDQtZjUwYS00ODUwLWI1MjAtMDExNDQ5YjlhMjc4IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiOUZDK1ptbmpzRkFwZFNBMVlxTW5NbTY0SzBiSWxpNHlLdnZUdFhGNjJma2ZcL093ZVRlWlg4bEtsQ1dHRlZhTmIifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v5] 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 12:28:48 -0000 Hi Konstantin, Thanks for your comments. I will revise the patch and submit another patch= later. Best Regards Ziye Yang=20 -----Original Message----- From: Ananyev, Konstantin=20 Sent: Monday, September 10, 2018 8:19 PM To: Yang, Ziye ; dev@dpdk.org Cc: Ziye Yang Subject: RE: [dpdk-dev] [PATCH v5] linuxapp, eal: Fix the memory leak issue= of logid > -----Original Message----- > From: Yang, Ziye > Sent: Monday, September 10, 2018 12:58 PM > To: Ananyev, Konstantin ; dev@dpdk.org > Cc: Ziye Yang > Subject: RE: [dpdk-dev] [PATCH v5] linuxapp, eal: Fix the memory leak=20 > issue of logid >=20 > Hi Konstantin, >=20 > The global logid is used to prevent the memory leak. If we do not do=20 > this, but directly free(logid), this pointer will still be used by=20 > openlog, which means that we cannot free the logid anymore. And by adding= the global variable, it will not only solve the memory leak but also makes= the openlog function still work. But then I suppose you can avoid any dynamic memory allocation at all with = something like that: rte_eal_init(int argc, char **argv) { ... static char logid[PATH_MAX]; ... const char *p=3D strrchr(argv[0], '/'); snprintf(logid, sizeof(logid), "%s", p); ... rte_eal_log_init(logid, ...); ? Konstantin >=20 >=20 > Best Regards > Ziye Yang >=20 > -----Original Message----- > From: Ananyev, Konstantin > Sent: Monday, September 10, 2018 7:55 PM > To: Yang, Ziye ; dev@dpdk.org > Cc: Ziye Yang > Subject: RE: [dpdk-dev] [PATCH v5] linuxapp, eal: Fix the memory leak=20 > issue of logid >=20 > Hi >=20 > > -----Original Message----- > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Ziye Yang > > Sent: Wednesday, September 5, 2018 6:39 AM > > To: dev@dpdk.org > > Cc: Ziye Yang > > Subject: [dpdk-dev] [PATCH v5] linuxapp, eal: Fix the memory leak=20 > > issue of logid > > > > 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=20 > > memory leak issue. > > > > Signed-off-by: Ziye Yang > > --- > > lib/librte_eal/linuxapp/eal/eal.c | 21 ++++++++++++++++++++- > > lib/librte_eal/linuxapp/eal/eal_log.c | 11 ++++++++++- > > 2 files changed, 30 insertions(+), 2 deletions(-) > > > > diff --git a/lib/librte_eal/linuxapp/eal/eal.c > > b/lib/librte_eal/linuxapp/eal/eal.c > > index e59ac65..e150200 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 =3D 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 =3D strrchr(argv[0], '/'); > > logid =3D strdup(logid ? logid + 1: argv[0]); > > + if (!logid) { > > + rte_eal_init_alert("Cannot allocate memory for logid\n"); > > + rte_errno =3D ENOMEM; > > + rte_atomic32_clear(&run_once); > > + return -1; > > + } > > > > thread_id =3D pthread_self(); > > > > @@ -823,6 +829,8 @@ static void rte_eal_init_alert(const char *msg) > > if (rte_eal_cpu_init() < 0) { > > rte_eal_init_alert("Cannot detect lcores."); > > rte_errno =3D ENOTSUP; > > + rte_atomic32_clear(&run_once); > > + free(logid); > > return -1; > > } > > > > @@ -831,6 +839,7 @@ static void rte_eal_init_alert(const char *msg) > > rte_eal_init_alert("Invalid 'command line' arguments."); > > rte_errno =3D EINVAL; > > rte_atomic32_clear(&run_once); > > + free(logid); > > return -1; > > } > > > > @@ -838,12 +847,14 @@ static void rte_eal_init_alert(const char *msg) > > rte_eal_init_alert("Cannot init plugins\n"); > > rte_errno =3D EINVAL; > > rte_atomic32_clear(&run_once); > > + free(logid); > > return -1; > > } > > > > if (eal_option_device_parse()) { > > rte_errno =3D ENODEV; > > rte_atomic32_clear(&run_once); > > + free(logid); > > return -1; > > } > > > > @@ -851,6 +862,8 @@ 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); > > + free(logid); > > return -1; > > } > > > > @@ -861,6 +874,8 @@ static void rte_eal_init_alert(const char *msg) > > rte_eal_init_alert("failed to init mp channel\n"); > > if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY) { > > rte_errno =3D EFAULT; > > + rte_atomic32_clear(&run_once); > > + free(logid); > > return -1; > > } > > } > > @@ -869,6 +884,7 @@ static void rte_eal_init_alert(const char *msg) > > rte_eal_init_alert("Cannot scan the buses for devices\n"); > > rte_errno =3D ENODEV; > > rte_atomic32_clear(&run_once); > > + free(logid); > > return -1; > > } > > > > @@ -893,6 +909,7 @@ static void rte_eal_init_alert(const char *msg) > > rte_eal_init_alert("Cannot get hugepage information."); > > rte_errno =3D EACCES; > > rte_atomic32_clear(&run_once); > > + free(logid); > > return -1; > > } > > } > > @@ -919,8 +936,10 @@ static void rte_eal_init_alert(const char *msg) > > rte_eal_init_alert("Cannot init logging."); > > rte_errno =3D ENOMEM; > > rte_atomic32_clear(&run_once); > > + free(logid); > > return -1; > > } > > + free(logid); > > > > #ifdef VFIO_PRESENT > > if (rte_eal_vfio_setup() < 0) { > > diff --git a/lib/librte_eal/linuxapp/eal/eal_log.c > > b/lib/librte_eal/linuxapp/eal/eal_log.c > > index 9d02ddd..076b1b9 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,18 @@ > > rte_eal_log_init(const char *id, int facility) { > > FILE *log_stream; > > + int str_len; > > > > log_stream =3D fopencookie(NULL, "w+", console_log_func); > > if (log_stream =3D=3D NULL) > > return -1; > > > > - openlog(id, LOG_NDELAY | LOG_PID, facility); > > + str_len =3D strlen(id); > > + if (str_len >=3D DEFAULT_LOG_ID_LEN) > > + return -1; > > + > > + strncpy(g_logid, id, str_len); > > + openlog(g_logid, LOG_NDELAY | LOG_PID, facility); >=20 >=20 > Could you explain what is the point here to create a global here and pass= pointer to it to openlog()? > Konstantin >=20 > > > > eal_log_set_default(log_stream); > > > > -- > > 1.9.3