From patchwork Mon Nov 11 10:38: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: 13870543 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 019C2189F42 for ; Mon, 11 Nov 2024 10:38:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731321536; cv=none; b=L/BKjfXMiuRcE2PRYsoQXh4wKw6mueUnESTyZAr/y4zv7u2Sx43a8yqbjIXw8hYdqJB212DUeocAFskP+7VnlQh8Cz/3oUssYMTyQo33ZH92JRV61GbW+d7vjKVEDN+9vVPUo+ryorYQC+xqbbLcWFi456r0yzyKIGcRj5OTzMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731321536; c=relaxed/simple; bh=K+4NJTDZLDbxI7Cv/0K3Pzg2hX1EY5xszX+RkxInH9Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kAgzuYkiFKhljJU+/RUX925msPfw6kRMajd4210QHQnzK3U+t0xWWXXsQfY3nRHxv5VB4VrmgSDBeaL3Vv9li47bqDezu8pMNKwSeDdoltHO9f23slXv5pyeYmX9H3ZsRDh6mSv/QR7bctf3irru4y7Gz0V3Xrk/i1qd9OE2+OM= 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=jkRaNcEI; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=c6Y/sFiU; arc=none smtp.client-ip=103.168.172.151 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="jkRaNcEI"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="c6Y/sFiU" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id 1176613801F5; Mon, 11 Nov 2024 05:38:54 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Mon, 11 Nov 2024 05:38: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=fm3; t=1731321534; x=1731407934; bh=+n0CumCDI+clQ9ReQlJQlO/QyzI5zyp9cGfEqreGZYM=; b= jkRaNcEIKfcTjIFpLhHTMzSlATB6aYpsCzb54SX5PbBbramX9bsyxL7qjCR8CW6h n8GlW0tBhZyFP6s1NnuOdiF+O8hu98TuS4k0xesJ1bb0Z3VMAbfipsD0Gx5V1QwB hzafzx9ASYUXA1TGrU9b0TSV1dekrHw47QMbYCu+37BDQFRE5g3cafM0W6OqZkv5 aUFfekABMC39LH/qOKIpnwuWVhg8yVEFnj5HGoNcHJgnJl7187ncr+vSWoQz03a4 BxjwaZ6qugdzH0mk+H+m+bfitFft4LLng/GvKrNgY4LZ7kFjRnayoZk+jviL48ru 1TCSAgmLXm23sNxmP/7lHA== 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=fm3; t=1731321534; x= 1731407934; bh=+n0CumCDI+clQ9ReQlJQlO/QyzI5zyp9cGfEqreGZYM=; b=c 6Y/sFiUY6b5MwYzATJOT82MopLEbn2f3GGOlSIlKHeDbfEAmIB7ng7M8ZhJ6aWop a8mJ2/AUKy0Qs9sISPxlZTqbfBb32+iTXIqmajLWZKRcMrII7kONtpM7AId0xLgd IpAppvhQ2UM1kPwDAmt3VdHUOH6URQXl7d0SgOdX0JpCshucPNV+STpwJmUvIfW2 +mxsREaaPd1xSErcE8Gz2ST/3BEVKo0CkfuusVMi73Zi2n1Gpw5yya6agGvYTqiT QJzQElD8EbQhLfyLS8CBbaYmHo58a9r6BTIwyTS81JPaUAjgvxapCKyeYLxD32Qc W0vR8ybNSOlQ4K9UrUzWA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddvgddukecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeen ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkeduheej teekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheprhhjuhhsthhosehgmhgrihhlrdgtohhmpdhrtghpth htohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 11 Nov 2024 05:38:53 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 64f3d87e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 11 Nov 2024 10:38:19 +0000 (UTC) From: Patrick Steinhardt Date: Mon, 11 Nov 2024 11:38:37 +0100 Subject: [PATCH v2 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: <20241111-b4-pks-leak-fixes-pt10-v2-8-6154bf91f0b0@pks.im> References: <20241111-b4-pks-leak-fixes-pt10-v2-0-6154bf91f0b0@pks.im> In-Reply-To: <20241111-b4-pks-leak-fixes-pt10-v2-0-6154bf91f0b0@pks.im> To: git@vger.kernel.org Cc: =?utf-8?q?Rub=C3=A9n_Justo?= 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)' '