From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 167D41B19 for ; Mon, 10 Sep 2018 13:58:49 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2018 04:58:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,355,1531810800"; d="scan'208";a="71753545" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga007.jf.intel.com with ESMTP; 10 Sep 2018 04:58:24 -0700 Received: from fmsmsx111.amr.corp.intel.com (10.18.116.5) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 10 Sep 2018 04:58:24 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx111.amr.corp.intel.com (10.18.116.5) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 10 Sep 2018 04:58:23 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.226]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.143]) with mapi id 14.03.0319.002; Mon, 10 Sep 2018 19:58:22 +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: AQHURNr7E3rktHeMwUq0FIlXiCdNO6Tk2RhAgASXvoA= Date: Mon, 10 Sep 2018 11:58:21 +0000 Message-ID: References: <1536125954-46632-1-git-send-email-ziye.yang@intel.com> <2601191342CEEE43887BDE71AB977258EA953A94@irsmsx105.ger.corp.intel.com> In-Reply-To: <2601191342CEEE43887BDE71AB977258EA953A94@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 11:58:50 -0000 Hi Konstantin, The global logid is used to prevent the memory leak. If we do not do this, = but directly free(logid), this pointer will still be used by openlog, which= means that we cannot free the logid anymore. And by adding the global vari= able, it will not only solve the memory leak but also makes the openlog fun= ction still work. Best Regards Ziye Yang=20 -----Original Message----- From: Ananyev, Konstantin=20 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 issue= of logid 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 >=20 > From: Ziye Yang >=20 > 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. >=20 > 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(-) >=20 > diff --git a/lib/librte_eal/linuxapp/eal/eal.c=20 > 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]; >=20 > @@ -812,6 +812,12 @@ static void rte_eal_init_alert(const char *msg) >=20 > 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; > + } >=20 > thread_id =3D pthread_self(); >=20 > @@ -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; > } >=20 > @@ -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; > } >=20 > @@ -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; > } >=20 > if (eal_option_device_parse()) { > rte_errno =3D ENODEV; > rte_atomic32_clear(&run_once); > + free(logid); > return -1; > } >=20 > @@ -851,6 +862,8 @@ static void rte_eal_init_alert(const char *msg) >=20 > 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; > } >=20 > @@ -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; > } >=20 > @@ -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); >=20 > #ifdef VFIO_PRESENT > if (rte_eal_vfio_setup() < 0) { > diff --git a/lib/librte_eal/linuxapp/eal/eal_log.c=20 > 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 @@ >=20 > #include "eal_private.h" >=20 > +#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; >=20 > log_stream =3D fopencookie(NULL, "w+", console_log_func); > if (log_stream =3D=3D NULL) > return -1; >=20 > - 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); Could you explain what is the point here to create a global here and pass p= ointer to it to openlog()? Konstantin >=20 > eal_log_set_default(log_stream); >=20 > -- > 1.9.3