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 5D9971041 for ; Mon, 10 Sep 2018 13:54:49 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2018 04:54:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,355,1531810800"; d="scan'208";a="79299732" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by FMSMGA003.fm.intel.com with ESMTP; 10 Sep 2018 04:54:47 -0700 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.54]) by IRSMSX103.ger.corp.intel.com ([169.254.3.234]) with mapi id 14.03.0319.002; Mon, 10 Sep 2018 12:54:46 +0100 From: "Ananyev, Konstantin" To: "Yang, Ziye" , "dev@dpdk.org" CC: Ziye Yang Thread-Topic: [dpdk-dev] [PATCH v5] linuxapp, eal: Fix the memory leak issue of logid Thread-Index: AQHURNr7E3rktHeMwUq0FIlXiCdNO6Tk2RhA Date: Mon, 10 Sep 2018 11:54:46 +0000 Message-ID: <2601191342CEEE43887BDE71AB977258EA953A94@irsmsx105.ger.corp.intel.com> References: <1536125954-46632-1-git-send-email-ziye.yang@intel.com> In-Reply-To: <1536125954-46632-1-git-send-email-ziye.yang@intel.com> Accept-Language: en-IE, 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: [163.33.239.182] 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:54:50 -0000 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 issue o= f 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 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 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 b/lib/librte_eal/linux= app/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