From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754595AbdKAMOD (ORCPT ); Wed, 1 Nov 2017 08:14:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5552 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752154AbdKAMOC (ORCPT ); Wed, 1 Nov 2017 08:14:02 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 420414E4C2 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jolsa@redhat.com Date: Wed, 1 Nov 2017 13:13:57 +0100 From: Jiri Olsa To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , Ingo Molnar , Peter Zijlstra , Jiri Olsa , LKML , kernel-team@lge.com, Jin Yao , Milian Wolff Subject: Re: [PATCH 1/2] perf tools: Fix memory leak in addr2inlines() Message-ID: <20171101121357.GA20353@krava> References: <20171031020654.31163-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171031020654.31163-1-namhyung@kernel.org> User-Agent: Mutt/1.9.1 (2017-09-22) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 01 Nov 2017 12:14:02 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 31, 2017 at 11:06:53AM +0900, Namhyung Kim wrote: > When libbfd is not used, addr2inlines() executes `addr2line -i` and > process output line by line. But it resets filename to NULL in the loop > so getline() allocates additional memory everytime instead of realloc. > > Cc: Jin Yao > Cc: Milian Wolff > Signed-off-by: Namhyung Kim Acked-by: Jiri Olsa jirka > --- > tools/perf/util/srcline.c | 7 ++----- > 1 file changed, 2 insertions(+), 5 deletions(-) > > diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c > index c143c3bc1ef8..51dc49c65476 100644 > --- a/tools/perf/util/srcline.c > +++ b/tools/perf/util/srcline.c > @@ -456,20 +456,17 @@ static struct inline_node *addr2inlines(const char *dso_name, u64 addr, > while (getline(&filename, &len, fp) != -1) { > char *srcline; > > - if (filename_split(filename, &line_nr) != 1) { > - free(filename); > + if (filename_split(filename, &line_nr) != 1) > goto out; > - } > > srcline = srcline_from_fileline(filename, line_nr); > if (inline_list__append(sym, srcline, node) != 0) > goto out; > - > - filename = NULL; > } > > out: > pclose(fp); > + free(filename); > > return node; > } > -- > 2.14.3 >