From patchwork Wed Nov 20 13:39:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13881198 Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (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 58EB71AB6CD for ; Wed, 20 Nov 2024 13:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732109997; cv=none; b=fuzaDK/SuqKw1doU2YNQ/Sh4P3URcYHXepQHFWz/irxOOWw9QFvWXwkumYo/VaPINJGBXRgG3DabfOrsxd9RL7dFCpLoiZpBVLvBCgZPNuqCQ16fghNOKo9LloX7YCsEI0tl4MgEL/WlsXjjHgo9I7JyxfPgfk8ZSBd/Y7KCSw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732109997; c=relaxed/simple; bh=G7WvZAUVv++KwM/xhvHPvls6A8BNIhnM92a60diVpCM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KsEh1uG1OSqwQ9EKDeV1QYAFzaUxfZmD0+3aThXjni57h2cGvsm4sRdjjdKzshxpAs5z82UshjUB1m/Mz2aFA4oQLICkqrGFJd3XucKf4J+zDwbAPsP4lhwhA8/mldbVE8Pb2vx2BO+SdgJwYdTILQUp9uB9p/PWJc/AntIEX3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=fCHaM+FT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Yawf3WSm; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="fCHaM+FT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Yawf3WSm" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 8A6A311401D0; Wed, 20 Nov 2024 08:39:54 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Wed, 20 Nov 2024 08:39:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1732109994; x=1732196394; bh=RMSGEiYpC0H9UDCAdTPScmbQYDQ6UEK/WihQv6nS1Ms=; b= fCHaM+FT4N51IE5uUI30Y19gzjNrBf+DehK4M9ttZlZY/xxN8J/DHWXe5wAKheWc hDIx4njCFW3XOej1cmRE4WeoaytLYfeB1vGKupDywxHg0az7KbOf4jWsiCKt1wfc 04FXP+uWPWhRmhasg5fJKcq1VZ2UYQLoOJuoIz/MKkGDKEKryZQzWzWSro5euNkJ uBQcotvPZyekeHx4//9+oq1aULerkpXFv+c+4dkDUBctDIYwx21GVp7dar22hngD pgWoLnBab97C7Htn4wum7u7ynXnX/mOo30boJCLkyhVoGvqln5W8PgisgyYYI75l 4Fn8nUqc6wNg62xW0/u2/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1732109994; x= 1732196394; bh=RMSGEiYpC0H9UDCAdTPScmbQYDQ6UEK/WihQv6nS1Ms=; b=Y awf3WSmRCm2/NOCXDbSWWl9W7JyEXYXUDhAwgiIr2jPp+KnG1skGhOwtSLhogncf X7aRCqUlgsRGe1tSL+81gJ3PJ4zaaM8WMzjhQTwEG7BlqFSUB7MQAdDXN0R36Xai NxTVB9CcL294wRKTDIqC9vDGKUhx+wuZy6ft20QJSiFUm1dpvn4HbE5X88Y6Zbfh lF5+AJq69I2jQGpVNQJP9c7dutX/G7nhkgtPQEskAKaU2U+1OoTUdcALRlXFNbxV bvWf5WCuYE+eEEHskpqGen5OjsiuUBxd52BEidaHYqhQHvmjG9ksLx1L1SkHmV8/ tGNukQFOo/OXPp2Gc/g+Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrfeeggdehgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeen ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkeduheej teekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheprhhjuhhsthhosehgmhgrihhlrdgtohhmpdhrtghpth htohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehpvghffhes phgvfhhfrdhnvghtpdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 20 Nov 2024 08:39:53 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f09028e2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 20 Nov 2024 13:39:01 +0000 (UTC) From: Patrick Steinhardt Date: Wed, 20 Nov 2024 14:39:37 +0100 Subject: [PATCH v3 08/27] line-log: fix leak when rewriting commit parents Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241120-b4-pks-leak-fixes-pt10-v3-8-d67f08f45c74@pks.im> References: <20241120-b4-pks-leak-fixes-pt10-v3-0-d67f08f45c74@pks.im> In-Reply-To: <20241120-b4-pks-leak-fixes-pt10-v3-0-d67f08f45c74@pks.im> To: git@vger.kernel.org Cc: =?utf-8?q?Rub=C3=A9n_Justo?= , Jeff King , Toon Claes X-Mailer: b4 0.14.2 In `process_ranges_merge_commit()` we try to figure out which of the parents can be blamed for the given line changes. When we figure out that none of the files in the line-log have changed we assign the complete blame to that commit and rewrite the parents of the current commit to only use that single parent. This is done via `commit_list_append()`, which is misleadingly _not_ appending to the list of parents. Instead, we overwrite the parents with the blamed parent. This makes us lose track of the old pointers, creating a memory leak. Fix this issue by freeing the parents before we overwrite them. Signed-off-by: Patrick Steinhardt --- line-log.c | 1 + t/t4211-line-log.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/line-log.c b/line-log.c index bca9bd804073df9b77b2859063ac5ad4d3b24e0f..bc67b75d10d34edc726c00c887d57016e40f3a00 100644 --- a/line-log.c +++ b/line-log.c @@ -1237,6 +1237,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm * don't follow any other path in history */ add_line_range(rev, parents[i], cand[i]); + free_commit_list(commit->parents); commit_list_append(parents[i], &commit->parents); ret = 0; diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh index 950451cf6a66e6c099aa5303ce19230c34cd1fc4..1d6dd982a2a858e9ca03635eb83b1463c9c9caed 100755 --- a/t/t4211-line-log.sh +++ b/t/t4211-line-log.sh @@ -4,6 +4,7 @@ test_description='test log -L' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup (import history)' '