Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp56133pxj; Wed, 16 Jun 2021 20:10:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwti9/3YPV8f7oYqIzxQJWD/S2t3kOVcstHcB53pguS7Ds46V2ktPwprKr6/C5YiGgQJW/G X-Received: by 2002:a05:6402:11cc:: with SMTP id j12mr3577871edw.114.1623899426863; Wed, 16 Jun 2021 20:10:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623899426; cv=none; d=google.com; s=arc-20160816; b=dS0PYKWCOr9c32Z9v24Kmf2cqdCMWV4MYCcitfClSmfhhKlnG12+DsgNdfiBzqEFRj 11rQsfC9+Ahqjg1KJUbFZxyFvlwRVV6VsA9qqlHmkC2A3gjLTOoiA5c4N9hfvbxKETw0 a8lcNXIggvKEqErrIqDKWyhOpOtJm+oxstSDkBMLe90T8El+KJm1ScVJcs2R7ntJFFXb qeQrFiqpXk76z+0yjcH0wkXQJnzDnnwh2p0yR7AbPHL35m37Q01FZST6zK6HrHIFztLg TcyQlUSPpkZkfeHrIlCv5lEhEx3ENX5hxFuvfnxhIAgBWkfQ3Rjkd1LGp/rOcSYD6tVl ujxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=HqygOLwBSZdtVdm3oS0+CcIHcGtDsb/e4LHNH8tNbJg=; b=L/1ITIJiCIB57Rc+7XTS0WMdNwScjKz6MYit8KVM04ZqxwAVrC/42qSu2BqMaSKWlu nm5cjTne5rmpz0VJ5PgZCCUznfPifl2e2gzpWLhg7q7C0FolP4WWSyvjBVhHhiuRbRzG iHsM0nGCClfcmytLfCgVNuG4DjU2uHucBQAXnN9coku/D51Qu9ObpadLqVPH80AzPEz8 PXtgqiSfFF7JNJTL46Ys1GuHK1vZ0LQ8glD6OdN4+3tSlbHy6tcq2FbICJvnBJC+7hAF +NFP4pYHbsZDbmG4SRBmBusHMwvhvudENOeqrv5aBSAQVOYwCvLGUPVHAbUxJr6WtlDh y7mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tmVFNsJn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w19si3677361edc.458.2021.06.16.20.10.04; Wed, 16 Jun 2021 20:10:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tmVFNsJn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231674AbhFPSOy (ORCPT + 99 others); Wed, 16 Jun 2021 14:14:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:59336 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231648AbhFPSOv (ORCPT ); Wed, 16 Jun 2021 14:14:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 95A07613B9; Wed, 16 Jun 2021 18:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623867164; bh=FVS8dvAqTX3/2tuOG6nrPzs64bbf6xagc9ZoBuR7k3c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tmVFNsJnRGywkjX1WEvwb9a5mDlyUXc1LJr6WzVn3GZSKh+Dhp3QcvszqfIktM5lc aUjQirir0bRB5qprx30jE5Qr0Snp9GyBz6sJ6mpOWi+mZUSUnpITbZgiC+s02the4M WhwUnhdbd4+7rZZQlc8RcDtXbfy9LxDvn/cAGi4lF2GugY/AtikFhqEtSLh6eaFcQV pU5TvQVmP3N4kaMVshWorptFFX7M5gjvgZgEseZy4tBH66LESpkx7BgAOhCauoQBd7 RVu1HilViuiATmoPWWa4bswrQjqe4E693npltfef50SC3bhlmpGYK1nKLDstWmT3lK 2GV/kVwM1sVhg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 281C940B1A; Wed, 16 Jun 2021 15:12:42 -0300 (-03) Date: Wed, 16 Jun 2021 15:12:42 -0300 From: Arnaldo Carvalho de Melo To: Riccardo Mancini Cc: Namhyung Kim , Ian Rogers , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Andi Kleen , Tommi Rantala , Jiapeng Chong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] perf ksymbol: fix memory leak: decrease refcount of map and dso Message-ID: References: <20210612173751.188582-1-rickyman7@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210612173751.188582-1-rickyman7@gmail.com> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Sat, Jun 12, 2021 at 07:37:48PM +0200, Riccardo Mancini escreveu: > ASan reported a memory leak of BPF-related ksymbols > map and dso. The leak is caused by refount never > reaching 0, due to missing __put calls in the function > machine__process_ksymbol_register. > Once the dso is inserted in the map, dso__put should be > called (map__new2 increases the refcount to 2). > The same thing applies for the map when it's inserted > into maps (maps__insert increases the refcount to 2). Thanks, applied. - Arnaldo > $ sudo ./perf record -- sleep 5 > [ perf record: Woken up 1 times to write data ] > [ perf record: Captured and wrote 0.025 MB perf.data (8 samples) ] > > ================================================================= > ==297735==ERROR: LeakSanitizer: detected memory leaks > > Direct leak of 6992 byte(s) in 19 object(s) allocated from: > #0 0x4f43c7 in calloc (/home/user/linux/tools/perf/perf+0x4f43c7) > #1 0x8e4e53 in map__new2 /home/user/linux/tools/perf/util/map.c:216:20 > #2 0x8cf68c in machine__process_ksymbol_register /home/user/linux/tools/perf/util/machine.c:778:10 > [...] > > Indirect leak of 8702 byte(s) in 19 object(s) allocated from: > #0 0x4f43c7 in calloc (/home/user/linux/tools/perf/perf+0x4f43c7) > #1 0x8728d7 in dso__new_id /home/user/linux/tools/perf/util/dso.c:1256:20 > #2 0x872015 in dso__new /home/user/linux/tools/perf/util/dso.c:1295:9 > #3 0x8cf623 in machine__process_ksymbol_register /home/user/linux/tools/perf/util/machine.c:774:21 > [...] > > Indirect leak of 1520 byte(s) in 19 object(s) allocated from: > #0 0x4f43c7 in calloc (/home/user/linux/tools/perf/perf+0x4f43c7) > #1 0x87b3da in symbol__new /home/user/linux/tools/perf/util/symbol.c:269:23 > #2 0x888954 in map__process_kallsym_symbol /home/user/linux/tools/perf/util/symbol.c:710:8 > [...] > > Indirect leak of 1406 byte(s) in 19 object(s) allocated from: > #0 0x4f43c7 in calloc (/home/user/linux/tools/perf/perf+0x4f43c7) > #1 0x87b3da in symbol__new /home/user/linux/tools/perf/util/symbol.c:269:23 > #2 0x8cfbd8 in machine__process_ksymbol_register /home/user/linux/tools/perf/util/machine.c:803:8 > [...] > > Signed-off-by: Riccardo Mancini > --- > tools/perf/util/machine.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c > index 3ff4936a15a4..da19be7da284 100644 > --- a/tools/perf/util/machine.c > +++ b/tools/perf/util/machine.c > @@ -776,10 +776,10 @@ static int machine__process_ksymbol_register(struct machine *machine, > if (dso) { > dso->kernel = DSO_SPACE__KERNEL; > map = map__new2(0, dso); > + dso__put(dso); > } > > if (!dso || !map) { > - dso__put(dso); > return -ENOMEM; > } > > @@ -792,6 +792,7 @@ static int machine__process_ksymbol_register(struct machine *machine, > map->start = event->ksymbol.addr; > map->end = map->start + event->ksymbol.len; > maps__insert(&machine->kmaps, map); > + map__put(map); > dso__set_loaded(dso); > > if (is_bpf_image(event->ksymbol.name)) { > -- > 2.23.0 > -- - Arnaldo