Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp268664lqh; Mon, 6 May 2024 20:12:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOJM0LQaDTb/U2J10e6mgC2qBwOXvUPk7iObi5t93QnmrLG/cF4AHiB5hczio1sbmNz2gM1ohIUsC0pV1VQuxV9DeIC9rTnf29LUeQjA== X-Google-Smtp-Source: AGHT+IF0fEP8G97p+ScZJEOKCR69iQM+o4+qjrK+qxJpHX18DDpj407ARuaDLLp2w+Q8R9vRBaTg X-Received: by 2002:a05:6a21:18e:b0:1af:8004:4be1 with SMTP id le14-20020a056a21018e00b001af80044be1mr13303909pzb.33.1715051557561; Mon, 06 May 2024 20:12:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715051557; cv=pass; d=google.com; s=arc-20160816; b=KTqF3sIGWyMIjJ00PZtA4Uubo5zEI28UzKhf93dnqCArZb0YqlRTNqgoQV5Nil5ZJc e0bmbC3Y8yE2HL7sP1QamgKFxJjepL9LIK3PL7nd/wKwpU3civSb44VNG0+5iJTcQPyW fESczMIaX3yTGGSYaa5QBL0qDtQJ/ocjwkXujLJ/xddKXXQ+Dcau9q4Opo4DcNuDK8f2 CnwpS8FzNoFrQsRpDNW/LUn739gjmhSWcEGYbBXLYB3jwtpUMQiRiJ+/L8N4YwtD/5q1 Mo96xSKBM4+x9IL7wzAVlJISDyYq2mky/3QUTlJ4b4K9w/RH55MLYXKYlAoV7GV6ykbl 9sKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=wpRtjCrbxeVCoO1+fg7IqTJpAlX9QG4LO1gMggHbwlY=; fh=0iP7KC8U49yjVojUGKQe85v+Ko9+oRjsym7pRdPoqlg=; b=B1wLAB8XSnv11qznED+/0H20YQGDOPyboWbQCGMuL7Gs6YIjvXb1I1hfoU36/oUFKH dviWOt0q+koJIJNibQv1AAXE9Wmvy+6vLTEYU4ZoH2uaseCO4ZkbcChG/3IK+Lf/fS+W mf32HI5ldddB/QaHU4roLK20CwnwPSEsX6wMUjda8CewcvLLPjY3imx3ZemwNJVDWlrx s2XHjRVgaCkpU3Uzbevqv93RNKmQTWQ8KS2RRhCLW34P54s94CcsknTNmzpupxfq5r/Z t2H8GzXyV4KO/9KeuuNcIOpQ6G0SHfS9NJf5Sto9BwclnN4IMgBnxBdvXecWBvz00pn3 S8Ow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pUcFPAPx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-170605-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170605-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e20-20020a170902f1d400b001e7d54c8bc2si9347675plc.254.2024.05.06.20.12.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 20:12:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170605-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pUcFPAPx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-170605-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170605-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 319EC2835C8 for ; Tue, 7 May 2024 03:12:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A69EF4087F; Tue, 7 May 2024 03:12:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pUcFPAPx" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC3F9441D; Tue, 7 May 2024 03:12:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715051549; cv=none; b=XEOwY+890VjvZizTdSO5p1e5jgYYp/gXGImjzrx4vsN5eCopTBZi4ZCSxTIR2za3ZsWON9dYstmJ12Y0jlgX9loiuWIFRFMJ3OLBaA0rWoe6uM67zT5YRkISy5/I6NuWVtKGaHGE+oDD70r4M1NhL0lvyOr+FzPKGKkkf9TeNnI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715051549; c=relaxed/simple; bh=pvlcwt643zOzwEXI7BQOtxjXGNgcPW5iawds7hOyeCw=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=gr+PNrumBHzOxQgMouYl3A30oqdh8vU8oWE/PehlP/EPSwKurGtkuYRc4+ey7q8soiiFDN/sQUiVgn70eOX8EOlVUj2T5rTpxt/IAChKyknto/dxVQ/VHtHHyGyESN22T2hVCQ2e1J9dPeMY6qfwRjD0PmO8FQXZ0/uwfp6nTYs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pUcFPAPx; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1066BC4AF18; Tue, 7 May 2024 03:12:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715051549; bh=pvlcwt643zOzwEXI7BQOtxjXGNgcPW5iawds7hOyeCw=; h=Date:From:To:Cc:Subject:From; b=pUcFPAPxdSmXRgaH5gJ8llhHF3ZQ3RkSPw6c/PhlGHCMkw5xiTgt2gfyCe/ft2yEu HD/WeCumDy9g8+FYboAO8oGWkziCRskU/Vc1geb5DJAzNW3E4Hn/5Vem+rWvowqcBm 0qOUYklhwiRKwRmTRBFed4Xp+xLzj4Dq/NSxDWKoHL8PfXyD1ZG7eefJbdShkEoKUd enj8o27nM5dF14jc7a3z/wdLoMz392k82TolaIMd7zBqcXClCUe7RHKv5AdqI1kGej 1qxv02T+evYrnNiF4ppiHFJxclIrzO9ikzgIEXn0fbpAUxyaeS0+b6kwvpKro2ZICu TlBt2X9zC29iw== Date: Tue, 7 May 2024 00:12:26 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Adrian Hunter , Jiri Olsa , Kan Liang , Namhyung Kim , Linux Kernel Mailing List , linux-perf-users@vger.kernel.org Subject: [PATCH 1/1] perf callchain: Use zfree() to avoid possibly accessing dangling pointers Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline When freeing a->b it is good practice to set a->b to NULL using zfree(&a->b) so that when we have a bug where a reference to a freed 'a' pointer is kept somewhere, we can more quickly cause a segfault if some code tries to use a->b. Convert one such case in the callchain code. Cc: Adrian Hunter Cc: Ian Rogers Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/callchain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 68feed8718096f78..1730b852a947400f 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -606,7 +606,7 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor) call->brtype_stat = zalloc(sizeof(*call->brtype_stat)); if (!call->brtype_stat) { perror("not enough memory for the code path branch statistics"); - free(call->brtype_stat); + zfree(&call->brtype_stat); return -ENOMEM; } } -- 2.44.0