From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Monjalon Subject: Re: [PATCH v8] linuxapp, eal: Fix the memory leak issue of logid Date: Sun, 28 Oct 2018 11:41:50 +0100 Message-ID: <2291161.Cnx30EFnGb@xps> References: <1536125954-46632-1-git-send-email-ziye.yang@intel.com> <1536715910-38320-1-git-send-email-ziye.yang@intel.com> <30207781.zVJTsycACh@xps> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit Cc: dev@dpdk.org, konstantin.ananyev@intel.com, Ziye Yang , ferruh.yigit@intel.com To: Ziye Yang Return-path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id DA4F72B91 for ; Sun, 28 Oct 2018 11:41:45 +0100 (CET) In-Reply-To: <30207781.zVJTsycACh@xps> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 22/10/2018 10:00, Thomas Monjalon: > 12/09/2018 03:31, Ziye Yang: > > 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 > > --- > > - 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])); > > Shouldn't it be strlcpy instead of snprintf? Applied with suggested replacement: - snprintf(logid, sizeof(logid), "%s", (p ? p + 1 : argv[0])); + strlcpy(logid, p ? p + 1 : argv[0], sizeof(logid));