From patchwork Tue Aug 20 14:05:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770147 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 5784E191476 for ; Tue, 20 Aug 2024 14:05:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162706; cv=none; b=GMIeKAcmh9YB2pRfICjZBQLFXAV7m5K7soMNPneXlLnRF++it9c7RnsbJhywJeQsIxt+sKeYpI6RxdBM9O5dF6dVveLcZpYimgfYzaKqfVEU2FIlxYLO/ArnKCC+m2UFazDuXAW6Fkn1INuFGYFC2smZSAm06WcsDFSqTz4PU4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162706; c=relaxed/simple; bh=JSmfvtR/Ct2tqfGDjOlz6UwxLrCiRpmHYB+uixyz8DU=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sESPGXBM7/eDG7PnLxJIxHKAGfSQH4iCiqIUQ75v5S8iSq4a1za9RQ7MkeIvnscRFNuNzLD4yKAcWRngGXAoqNBDhsU3Rmq0Dlia7uG2OsUsTJ7GvFytY0Z7MK6WwDdn84MoKwwOkCRvsfgXJnzvflECg/g4imSqf9TeRYa+xy4= 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=Ohc/uhH6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Tkx7xXzR; arc=none smtp.client-ip=103.168.172.148 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="Ohc/uhH6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Tkx7xXzR" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 6AABF138D263 for ; Tue, 20 Aug 2024 10:05:04 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 20 Aug 2024 10:05:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162704; x=1724249104; bh=osC24z7dhB sS6tpvNcPKRxMjKSKUX0C6NSUaScxGReA=; b=Ohc/uhH6+2H90UvV38pk3sTd7n N3E6moXgWbAGxwU3aWbDibq9wvOvlMF+/SxMzaOBtoAF3uS6SZc+v1kgkfiWjPfU gkYkWJFyQm+5AWKkeTDidKjffB20HW9O8VU3p8UXPN8xnq2jY/zLY47iFFDIJE9H F62nHFcgPeIfvQ9ZlU9J6jL5n+rSVSqzS5a/K9n6Pmne8phMtjPyCcwb1INpd8Uf JbcWlLkIs2aJd5Fk4AdlRrKesNcOMMz4jdnfRhyUpDoTAHmMr7tU/eQo3LfJJOP8 yKPZrQDgGDJR4Eg6zsYtcxXCb/K4X7fdHMkqGKeLUD/ZBMKuKmvddwKfs7gQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162704; x=1724249104; bh=osC24z7dhBsS6tpvNcPKRxMjKSKU X0C6NSUaScxGReA=; b=Tkx7xXzRunMLk4lskhO4TDCehcCCNz2WjlvwYyYN3f0x 1Yh6yCktUZ1nTYMkPA3tlaiplePeZXYAqz6olsc7wYe6HPKlUS5q3OdV7R8+jXiX pdpN3joi5S6JAZlIfxlWgy+zXW1KqXX6LwTfK/7FLzz1pFnauSdW6vAERW1yV2na kKDlLEBBbj49Wy57u1qnNe1i2P75Wllt9lJ0HkfpXbt1v/Ts34ku1mz1Esw1zF1g JlV19i7COYBGedgewf9pb4yg0rbTZWPHW7OPN4jT+iOWTRKRFoRD+0bPvP0W5TI9 F0w1VpWuAWPBuehJHxnErSl2bjpl1OjA8bClTrckiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:03 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 2ec8664d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:04:32 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 01/20] mailinfo: fix leaking header data Message-ID: <69e30ea5179eff6472be54ebba64ebca3e562f32.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We populate the `mailinfo` arrays `p_hdr_data` and `s_hdr_data` with data parsed from the mail headers. These arrays may end up being only partially populated with gaps in case some of the headers do not parse properly. This causes memory leaks because `strbuf_list_free()` will stop iterating once it hits the first `NULL` pointer in the backing array. Fix this by open-coding a variant of `strbuf_list_free()` that knows to iterate through all headers. Signed-off-by: Patrick Steinhardt --- mailinfo.c | 17 +++++++++++++++-- t/t5100-mailinfo.sh | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mailinfo.c b/mailinfo.c index 94b9b0abf22..a4fa64994ac 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -1290,8 +1290,21 @@ void clear_mailinfo(struct mailinfo *mi) strbuf_release(&mi->inbody_header_accum); free(mi->message_id); - strbuf_list_free(mi->p_hdr_data); - strbuf_list_free(mi->s_hdr_data); + for (size_t i = 0; header[i]; i++) { + if (!mi->p_hdr_data[i]) + continue; + strbuf_release(mi->p_hdr_data[i]); + free(mi->p_hdr_data[i]); + } + free(mi->p_hdr_data); + + for (size_t i = 0; header[i]; i++) { + if (!mi->s_hdr_data[i]) + continue; + strbuf_release(mi->s_hdr_data[i]); + free(mi->s_hdr_data[i]); + } + free(mi->s_hdr_data); while (mi->content < mi->content_top) { free(*(mi->content_top)); diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh index c8d06554541..065156c1f39 100755 --- a/t/t5100-mailinfo.sh +++ b/t/t5100-mailinfo.sh @@ -5,6 +5,7 @@ test_description='git mailinfo and git mailsplit test' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh DATA="$TEST_DIRECTORY/t5100" From patchwork Tue Aug 20 14:05:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770148 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 38B7819148A for ; Tue, 20 Aug 2024 14:05:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162710; cv=none; b=a+gxahQ9gLJgjpzEAbA0tXrHTsD4SyUvvZOSl6Zf6AFnTXm1dp+KMfH2gRn3l2Sv/K8Henk0MNpzXFnCQXqPy8ZSekn6moo3F4zFsfvBFQ1LShWhLcIGqiL/evngyA+7JFQiNMI1iRcTorKa8b67Ep9lJExXIvo7nWT0VhD0m7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162710; c=relaxed/simple; bh=otBYJDTv0gRId/5uczKSEggpmDaJ+3GgLHUhS1ux0sg=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nNt04ykFqH2CsjFQoHIUgR8abk7h+51WwXCAYlPwWGcpdgSRPSrR72z/MYj7btp+1bLajdAIoVkvLIucpxG0DxueARzXtaSpJZhVWvKJhh0jra4vf0xPpK0Q9Jg30byWKZLDIWgAZNCfFUeO4sG6kBRJxBJ7gS4itlnNypjeKOE= 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=Lt1+pTUt; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=c1leEA5A; arc=none smtp.client-ip=103.168.172.159 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="Lt1+pTUt"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="c1leEA5A" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 5C7591151A9C for ; Tue, 20 Aug 2024 10:05:07 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 20 Aug 2024 10:05:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162707; x=1724249107; bh=dn6/T2X+tl LtK6xfey+zjja8ro5u/5BaC0FCx5P/YkM=; b=Lt1+pTUtKOo1GVIUWfEcKHcKtV uNuQMGe6Dt3HlJjTb2O/V4Qe0jIakdi9dnL8vIrL/0GTm2bfCNLD+VuFjAkThenS 74ttad5k4PL8a4DTaKMDLQL5AliYZ6B7dWCQamwCojgYZq+v+95SqVt75fUO4teL FunYoXROK5LzvJLiVQM01S/XnKQ2P5lz4wnBTPrGm2OeE58O9Nc4qbOQHqDhA0zI 7A2OK/32OdYPZBqSD4R9D/n6wBpbFEBpBfQGWg/FHBPy5WTjNizpFfNFd0g5kprJ jBK55EOxY9/3wpgDbT0yCDudm0qtZfnzoKQuwDpiYXPjZgVMsc8Jji3rc+SA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162707; x=1724249107; bh=dn6/T2X+tlLtK6xfey+zjja8ro5u /5BaC0FCx5P/YkM=; b=c1leEA5AegFKkWQ+ExN2DseGRlHMvLRiKTCugpKAbuOw pbYi3uoD4lLVUoedftK4f3R13Og46lpDHGarmVzwf/AMclmX7wvpoCP69161mQJV uO+lC3TlqZ02QK7aon/fHzo2mdTSQU6oBrXtYuvN/sXWC1h8o3dUF/hYnllUj82L Tsj6DSeZTkaIouQQBx3CEmpX5CSJr/WRkJKeTaV5U/lZCtdTmzf7NFsgZYzGuzHt oBvztD0fqlt3Koi8NffCs4IwppLDFf2LW3PJIw7mBm/mUJKcSVY6sdjZd+7Dv7f6 2pFM9NoUGhWRwLu7yiOSFO9TU6ByB09xlZl0giO5hw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:06 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 124dc988 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:04:35 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:05 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 02/20] convert: fix leaks when resetting attributes Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When resetting parsed gitattributes, we free the list of convert drivers parsed from the config. We only free some of the drivers' fields though and thus have memory leaks. Fix this by freeing all allocated convert driver fields to plug these memory leaks. Signed-off-by: Patrick Steinhardt --- convert.c | 3 +++ t/t4150-am.sh | 1 + 2 files changed, 4 insertions(+) diff --git a/convert.c b/convert.c index e6184d21f26..c9a31eb4f03 100644 --- a/convert.c +++ b/convert.c @@ -1371,6 +1371,9 @@ void reset_parsed_attributes(void) for (drv = user_convert; drv; drv = next) { next = drv->next; free((void *)drv->name); + free((void *)drv->smudge); + free((void *)drv->clean); + free((void *)drv->process); free(drv); } user_convert = NULL; diff --git a/t/t4150-am.sh b/t/t4150-am.sh index 5e2b6c80eae..232e1394e8d 100755 --- a/t/t4150-am.sh +++ b/t/t4150-am.sh @@ -5,6 +5,7 @@ test_description='git am running' 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: messages' ' From patchwork Tue Aug 20 14:05:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770149 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 9C368191F8A for ; Tue, 20 Aug 2024 14:05:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162713; cv=none; b=biViN4TwL2ByNAgBcVAzDhnLJ40YYUprE0qWFWO1aDgnQJmvgl1o4etUOVzUdzqfM0Hj8rJhjljcRKuLnupJFFZfXUMYDUMJrPqaoRc2ge6P30NaXBCZqn0rgkaDAn5g25OKfinEO3jiXQCRw5fGYLBkkg5Imc0/s0QLJMP0+is= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162713; c=relaxed/simple; bh=u6BC6mmj5NKTyFYQsNNGowPPEXLi/85qwssdjA4Gcj4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KPBBi6ixVD1oTzgVdqp+eTmIEe4zr6AI3gQ0UIzaunsPBcCWSuiLYyWNATkbsa4hiZum91llagavDNAQftmTOSdVY5K9LT8jMonNKRjDdfcAVjTBZblSXHY2z+AQHnLcw3KVTqLNZIHHzibATEgD2w/KDXg9IWUvrkIQAJlCrm0= 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=rW78t6rb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=BoXltB7q; arc=none smtp.client-ip=103.168.172.159 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="rW78t6rb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BoXltB7q" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7AFFD1151A89 for ; Tue, 20 Aug 2024 10:05:10 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 20 Aug 2024 10:05:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162710; x=1724249110; bh=Snw0jvtwxT o/7W6+4Fw+sDMpgouwrcVw5ViBFUmoZI4=; b=rW78t6rbj5oREXxMnFMCyaMawE alQqwvzfF5yhxv50q4/eIpgL45DapEN6FKNHTXISiQ/xmTs646e15DIHeHEIUSky +H/k6NNStN6tGimZubxLFn1dE3O/jqUmwb7183Qm0IlS8e5NwppsgvJS+W38Gnxe ayUQa6mT53SN1tkTjJI+Q7uzkPzhmH56ynRd9D0y2F5XBjKyb6h4V2BT02WFpBpV ReA3ROFikg3bjHsJ1TROT1NYARIJlp9HRJIRV0aVEMaYkpf/2YtryHVG0F2ODTaF 2ncCxw/LZgqbXJnEEX2PUuGd7dzpfpM6skcrQaz+3mnOiPF5V9x2PV1Oy7xg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162710; x=1724249110; bh=Snw0jvtwxTo/7W6+4Fw+sDMpgouw rcVw5ViBFUmoZI4=; b=BoXltB7qzOCaVYArM+BmI9Ti2rvog0rSbWylZvGcbGyO Ln+Cy0xnfF/fJ0SC8lX88ji/O9ZASlmc868WzSLC5KcOnn1L+/Jgdrr8Knr8ootO Me4DExNgKnsBj2pktXi/+OkrjdoodNQH3mDNXhbfWuEzoaLnVYYmoiNFYfr4vyMX XiR1+hKAA7BWZnyGI57oAZUV8vzeSFpjWWxQSrK3zaFDa+k0sSr8kKLj864OAY+D LscyQBAw63BZChQniuj4sTY+fs8KvKiBUe8kZkTf5FvJ8w8L5iLAre751204flnO 82wHr7QR0ET7Wc/i2BQmz1A7txmsUCO01KHXU7tFnw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:09 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 532195f4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:04:38 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 03/20] pretty: fix memory leaks when parsing pretty formats Message-ID: <82f3908f9620cee29e36a51f6d18ddcc8392b966.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When parsing pretty formats from the config we leak the name and user format whenever these are set multiple times. This is because we do not free any already-set value in case there is one. Plugging this leak for the name is trivial. For the user format we need to be a bit more careful, because we may end up assigning a pointer into the allocated region when the string is prefixed with either "format" or "tformat:". In order to make it safe to unconditionally free the user format we thus strdup the stripped string into the field instead of a pointer into the string. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- pretty.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pretty.c b/pretty.c index 44222fb83c6..af8f433cdcb 100644 --- a/pretty.c +++ b/pretty.c @@ -63,7 +63,7 @@ static int git_pretty_formats_config(const char *var, const char *value, void *cb UNUSED) { struct cmt_fmt_map *commit_format = NULL; - const char *name; + const char *name, *stripped; char *fmt; int i; @@ -90,15 +90,21 @@ static int git_pretty_formats_config(const char *var, const char *value, commit_formats_len++; } + free((char *) commit_format->name); commit_format->name = xstrdup(name); commit_format->format = CMIT_FMT_USERFORMAT; if (git_config_string(&fmt, var, value)) return -1; - if (skip_prefix(fmt, "format:", &commit_format->user_format)) { + free((char *) commit_format->user_format); + if (skip_prefix(fmt, "format:", &stripped)) { commit_format->is_tformat = 0; - } else if (skip_prefix(fmt, "tformat:", &commit_format->user_format)) { + commit_format->user_format = xstrdup(stripped); + free(fmt); + } else if (skip_prefix(fmt, "tformat:", &stripped)) { commit_format->is_tformat = 1; + commit_format->user_format = xstrdup(stripped); + free(fmt); } else if (strchr(fmt, '%')) { commit_format->is_tformat = 1; commit_format->user_format = fmt; From patchwork Tue Aug 20 14:05:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770150 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 4BCEF1922C7 for ; Tue, 20 Aug 2024 14:05:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162714; cv=none; b=DSlhcanefxhGxJRKvBV+Cdpx9+ZJ8WS/ohDkbsNIFusmBj8e0voAfbMAwB41hYFQqGGyKJIBcDo06bElbgfJKp8alKyGVjtYSIwlLKJ78T1N/jcw6R4G48XT3B29icWHfpQO2ax1bRqHwWarrRHbUKTgTyL8jt3BNHWlag128/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162714; c=relaxed/simple; bh=P5drRehIGea+ag3xyfV65e0jcQew4diTYUjbw+m4vkM=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=opRopTNfwmBriGXpSI6JgLj88+HQS5GKXPRf9MFE5xXFURdUzsvC7WNMaO4t+1UcleJWpMKGtVkmpMRJU/Kqgn5VSciNfX3REkO0YiPMv0LqiytkLBmeNrXchzVKY1v2Uvo7/Ezgv+dMPlupzPOKupHDbyruiHahR/Dmz6eAL1Q= 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=jnGwFtOq; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=aj7PS3j+; arc=none smtp.client-ip=103.168.172.148 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="jnGwFtOq"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="aj7PS3j+" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 7662B138FC5F for ; Tue, 20 Aug 2024 10:05:12 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 20 Aug 2024 10:05:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162712; x=1724249112; bh=gIqz7cvmrU YU5R0PzCrSfb5630P5WWOl03TGpFeXqw4=; b=jnGwFtOqCIaHoavjXK58WG//+i o5DpchX9qqpZTpwOUtmPbsFS9pifvfz3wMZPfzTUMsdVMhPPqk9fpXcarq2FxhAm 2iwr42dVu/fV2rxQ3n8jq4YIulmQ+Sqyh8ZoJhcyAUfIxdru9B5e7iGCouofYUK2 t+buDfBS8DlxPEv2W9VW6K7wqn2PGDj2gpVh276NVaAVv2s0KnZoSgDronvfb/q5 oF7ZolAv8trfM3suqvjV5893D9g06SyD3YkwWjB0QEGHdbE+g7UaxgqftTobGs5w 4DgL4lLClMohU4VQ3gXd++k0Q6HZULM+bdNEW4y3eCOH9nw+cGlZAM31Oo4w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162712; x=1724249112; bh=gIqz7cvmrUYU5R0PzCrSfb5630P5 WWOl03TGpFeXqw4=; b=aj7PS3j+Popo/uN4J9fx+bcJ12JOERYgr4tx8HvInTSm 1fj4f7EPCp9ZGdsekTCENg7EpMIS22nsfan2RvURkHzcLI0qsPd5Uw6sVh6No1No E0bAfFfP3MzbG3tQSQ2MTMuMHb6d2ZZuicvpdO+xZ0R1JyYx2y6mHzNt6qMABe2y vMa4d21BwhBEgKNyAVbRg0cadfmwmWXOU7uGSfGhbAUD6QNIZXOHrr29uiPtKaJu n5M8B8THp9rf7x//+jSTm3B825enhpfeirHEazYPoZ97rpbx/87fPs5mnMjDbZP4 95/BWaZIFO2KHI7/9yvTRIksSQjNBg++Ib3dIpJgGQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:11 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 92178409 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:04:40 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:10 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 04/20] pretty: fix leaking key/value separator buffer Message-ID: <696467780e6a1b3d6050987c9305ff48213e306d.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `format_set_trailers_options()` function is responsible for parsing a custom pretty format for trailers. It puts the parsed options into a `struct process_trailer_options` structure, while the allocated memory required for this will be put into separate caller-provided arguments. It is thus the caller's responsibility to free the memory not via the options structure, but via the other parameters. While we do this alright for the separator and filter keys, we do not free the memory associated with the key/value separator. Fix this to plug this memory leak. Signed-off-by: Patrick Steinhardt --- pretty.c | 1 + t/t4205-log-pretty-formats.sh | 2 ++ 2 files changed, 3 insertions(+) diff --git a/pretty.c b/pretty.c index af8f433cdcb..6b684d7b828 100644 --- a/pretty.c +++ b/pretty.c @@ -1776,6 +1776,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ } trailer_out: string_list_clear(&filter_list, 0); + strbuf_release(&kvsepbuf); strbuf_release(&sepbuf); return ret; } diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 158b49d4b60..eb63ce011fa 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -5,6 +5,8 @@ # test_description='Test pretty formats' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Tested non-UTF-8 encoding From patchwork Tue Aug 20 14:05:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770151 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 9CC601922C7 for ; Tue, 20 Aug 2024 14:05:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162718; cv=none; b=QWWBq46MvPVi7gKU2j1j2uu6Tmu8s7GfoKloxrcL64XbKWgz+oQt2HsIITwGMAtWGTRK577clkWNlODrQg9ybcKSrpK8pQ3jCjGAtO7R5sdDnpF5PygIbIHUseuHum8GKRoMWArzCwsx5ftEeUdoRRLILdmvRSyRdmBM8y4+NcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162718; c=relaxed/simple; bh=mcRQa9G7hy7QauywfNNmby8ICn9wUCkZYmWcBv9yqGE=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HEJS+uf8Vgieo/Rtuna9e7VWJVltKocZ8hXQXQ7qOhPK5ik7kzU8s6gpYjq/MCtgQaN7jdLPCe8lreV2OTGwUEYoaFzUShvi9MjygvQDNwEDIYJkX02Ey+IGKzv4NGQrq1lMVbPmbeaE3L7xYQFSq0UsCQnfzvppdnBxPVqY9Ss= 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=cXm25ofa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=C7kkGRlM; arc=none smtp.client-ip=103.168.172.159 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="cXm25ofa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="C7kkGRlM" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id C6DDD1151AA6 for ; Tue, 20 Aug 2024 10:05:15 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 20 Aug 2024 10:05:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162715; x=1724249115; bh=HX6AGxmsBS j0RUbqpwNe1xuthWI35IE6uoPJO6H0/dQ=; b=cXm25ofaHu72QWoHNG1jVSwRcq WUhXQ63/KbO0aSdN93WO2KoAyECGutL6AHLcAs36WsjBfAJdoF3gFzhXaDx8AZES O5MspKQmR/9zZ0TD43STyBwCEDqIEuR4sO+/RvfP5i5u63uqMK4FvXqSnaCzkNV6 I4wTu+7IL6vAo6M/6o/FlSsD2F6vqxR+dxzVaCAefR1lhdQn6Eo8jwfGrt5CfXQJ h8yb8QwUWt+H+wzS3jijkaesGX3gMU5vfEcObjtgyizk2WHn89wifAWTFaPLll+w nfAyNZoGr13KxGRf7JcnlnvaSHZcR65h4Qx7zrU8vEN/AEydQ8ImQ6noD5Kw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162715; x=1724249115; bh=HX6AGxmsBSj0RUbqpwNe1xuthWI3 5IE6uoPJO6H0/dQ=; b=C7kkGRlMpWypJoAH4RdMA26s5OA5M+xIhhJOC+l+Gdw5 +lQDnrYy3c3RI8H7zukN5MmZK00k6rx00H4naNb+p/iDFQ7+CbauPxNGMkxy0u0q e3zZCe6+qc+iUBfmiblgfq+9yJ1PZJYDNsbmYXbNDaji4Zfsqq8fVvv6I6rm5iip pu18Lsy22Jydkt2DAkdglkmt8KcGEIxwHtbdmY9LlAqt3xLr2FJ3Bvykx3sSiTj6 kePL6Dk4xjUfXBCONyx/AepoH1rrqFaj181PAKu8t3FGU7373Mgsw2OXkjRXdlhn LrtJTHOd9iV6Z6Pd7mA/Xor1gkdvc9W2gHou0n84jA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:14 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 22c054df (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:04:43 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:12 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 05/20] builtin/merge-tree: fix leaking `-X` strategy options Message-ID: <53db2fc7206cc11cae4930eba8c413fce4715afb.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `-X` switch for git-merge-tree(1) will push each option into a local `xopts` vector that we then end up parsing. The vector never gets freed though, causing a memory leak. Plug it. Signed-off-by: Patrick Steinhardt --- builtin/merge-tree.c | 13 ++++++++++--- t/t4301-merge-tree-write-tree.sh | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 9bca9b5f33c..c00469ed3db 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -533,6 +533,7 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) int expected_remaining_argc; int original_argc; const char *merge_base = NULL; + int ret; const char * const merge_tree_usage[] = { N_("git merge-tree [--write-tree] [] "), @@ -625,7 +626,9 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) strbuf_list_free(split); } strbuf_release(&buf); - return 0; + + ret = 0; + goto out; } /* Figure out which mode to use */ @@ -664,7 +667,11 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix) /* Do the relevant type of merge */ if (o.mode == MODE_REAL) - return real_merge(&o, merge_base, argv[0], argv[1], prefix); + ret = real_merge(&o, merge_base, argv[0], argv[1], prefix); else - return trivial_merge(argv[0], argv[1], argv[2]); + ret = trivial_merge(argv[0], argv[1], argv[2]); + +out: + strvec_clear(&xopts); + return ret; } diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh index eea19907b55..37f1cd7364c 100755 --- a/t/t4301-merge-tree-write-tree.sh +++ b/t/t4301-merge-tree-write-tree.sh @@ -2,6 +2,7 @@ test_description='git merge-tree --write-tree' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # This test is ort-specific From patchwork Tue Aug 20 14:05:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770152 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 A1615192B75 for ; Tue, 20 Aug 2024 14:05:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162722; cv=none; b=mfVH0m79U1F339DsvljC1utQCeK+LSS65f2vo8pFdNhXHLbo6PH7dn68dBbiPhz0LoYNiJOW7PLM2Qm5P5jRuHXlHzudW17ifgZ502Uz2IUNk2U275S6kcxfBK7AZG66/vccOocGDtKO2oIEN1c67TqcsM1z2UYUqXn6/lNvhvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162722; c=relaxed/simple; bh=RD/cK3mC4lUaj4UwE53PpF5kS6UriEKuPl2+kl278jc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Nna1qPtT3rPhIgbbkmqJ52eooajBhgDR8IzRLR3grghpaAL6T8Gg1C+tA1Brh1ScZZ7pxUEkrn46HbxXVWqNj65KYKAl+Sl3asTTtOzhsNLOXsFjXNhstCBjJ3Ub1Ttcjpuhr/9p5mPCDfWNNtC3+bYzJiSCzibcdYLXjaQrFjA= 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=VUfvsNyS; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=e9k7qs0E; arc=none smtp.client-ip=103.168.172.148 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="VUfvsNyS"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="e9k7qs0E" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id D4924138DE37 for ; Tue, 20 Aug 2024 10:05:19 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 20 Aug 2024 10:05:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162719; x=1724249119; bh=TkdvvUFQnX JW9DvvlXb0iAfv/ehBZynAZUdHVdUP3yA=; b=VUfvsNyShD29wlf5tlYYfYK7H2 pdfILzXdxe+e5rP0Us0gaGdundqlJDHHt9attz95fVer2x6qL+Pdt8U9qFu6BLau CJskFqatv56iEY0q3aNJzG5Pg48n0DTc0pOdKrOicpdFtLFaNKqEsZ4LV9cX4FRI FKYfgV91eFc4RR30HpSm0bBXSGZNjeyZN+A8o6pHM/sEFBrcYJ4/aWGcq1qw0bWx FMTydPWoxtUaGGeX0Dt8ll1kPaZFVBmwgXvFo0gyl60NRnrVZi5fBcbOtjkfRU7g ZG18D8qywJr9IoCLe/iEokxIBB1xhraQW8SLcm7It9CMuwt34MA2lg56RDDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162719; x=1724249119; bh=TkdvvUFQnXJW9DvvlXb0iAfv/ehB ZynAZUdHVdUP3yA=; b=e9k7qs0EdjOOrXpGGngAmgaTpahhUKNyJf7kSPhkfAb6 REKzdHrXqCDJoVnBjDWRwGU6470Q9dmmyYZMtOuJ2pwuzvpNLRBNeVQ9ukF+9Ku1 qTIu6N83xhFehM2VZrZeEwSvFswFEWdmAKd4IZmFu1ue5WzBtLNZ+bYa+wFbP7tL OGfkaiDRQJbEKDUQkZ4JrsecvXBD4LOpKmRCbLpBKkIw+yllujo8eWieHLXk85Ne 0De3wfd/NmQMX+x9JRY6bxTEFidrBEmzLz6m48b7gejpUe5Y6gnLvQ8ABqZ0y71L DOvXUCnfGEefDAvx3kZGM7Gzzj89DwVm7BERspHcvQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:18 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 643cc76b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:04:48 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:15 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 06/20] builtin/upload-archive: fix leaking args passed to `write_archive()` Message-ID: <5b05a3252185d2cc817006ef587a44b423b8bea6.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In git-upload-archive(1), we pass an array of arguments to `write_archive()` to tell it what exactly to do. We don't ever clear the vector though, causing a memory leak. Furthermore though, the call to `write_archive()` may cause contents of the array to be modified, which would cause us to leak memory to allocated strings held by it. Fix the issue by having `write_archive()` create a shallow copy of `argv` before parsing the arguments. Like this, we won't modify the caller's array and can easily `strvec_clear()` it to plug these memory leaks. Signed-off-by: Patrick Steinhardt --- archive.c | 10 ++++++++++ builtin/upload-archive.c | 8 ++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/archive.c b/archive.c index 7bd60d0632a..9ba96aae4f7 100644 --- a/archive.c +++ b/archive.c @@ -736,6 +736,7 @@ int write_archive(int argc, const char **argv, const char *prefix, struct pretty_print_describe_status describe_status = {0}; struct pretty_print_context ctx = {0}; struct archiver_args args; + const char **argv_copy; int rc; git_config_get_bool("uploadarchive.allowunreachable", &remote_allow_unreachable); @@ -749,6 +750,14 @@ int write_archive(int argc, const char **argv, const char *prefix, args.repo = repo; args.prefix = prefix; string_list_init_dup(&args.extra_files); + + /* + * `parse_archive_args()` modifies contents of `argv`, which is what we + * want. Our callers may not want it though, so we create a copy here. + */ + DUP_ARRAY(argv_copy, argv, argc); + argv = argv_copy; + argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote); if (!startup_info->have_repository) { /* @@ -767,6 +776,7 @@ int write_archive(int argc, const char **argv, const char *prefix, string_list_clear_func(&args.extra_files, extra_file_info_clear); free(args.refname); clear_pathspec(&args.pathspec); + free(argv_copy); return rc; } diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index 1b09e5e1aa3..313a8dfa81c 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -22,6 +22,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) { struct strvec sent_argv = STRVEC_INIT; const char *arg_cmd = "argument "; + int ret; if (argc != 2 || !strcmp(argv[1], "-h")) usage(upload_archive_usage); @@ -46,8 +47,11 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) } /* parse all options sent by the client */ - return write_archive(sent_argv.nr, sent_argv.v, prefix, - the_repository, NULL, 1); + ret = write_archive(sent_argv.nr, sent_argv.v, prefix, + the_repository, NULL, 1); + + strvec_clear(&sent_argv); + return ret; } __attribute__((format (printf, 1, 2))) From patchwork Tue Aug 20 14:05:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770153 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 94BCE1917CC for ; Tue, 20 Aug 2024 14:05:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162726; cv=none; b=VL4uzl5zJOg7k1w1ha0KeoV9nzGLbU2+SdVRNsUY4T77keO64ytOykVIIUDFzI67VVvJSdT128MvjOUc2v9c0QRxxrimge9kPy/SNjLRI24Lss4pFXPHjFJ3YbTF/fdIxtEgfRSc+Y7lW9m+ifuVDVOeQD0uckRRPyVbkZvlV/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162726; c=relaxed/simple; bh=+efCFzN5AJynIXOyAn8If4Vqm3JpKtRIWXMyvKo6mk0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WrSC1nA1kAIoT4jA+JGs/y2TtFTzYTIqq6Zu6W5OG9Y+1DVi5l0yv/lbOJQW6lfxKxh0SRc56kkV09AZ0HZKmj1mPAe21WLX4f4xLnstaLISkCMA2QvH1hGNSojR2JzdvdqFF3B9LQ/4fSztVsgKtRikHAMjqX9DA/+RFqyqGI8= 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=Upy595PG; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FJcOHGLS; arc=none smtp.client-ip=103.168.172.159 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="Upy595PG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FJcOHGLS" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 4BD771151A9D for ; Tue, 20 Aug 2024 10:05:23 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 20 Aug 2024 10:05:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162723; x=1724249123; bh=bAkMX/B++S 8eeyt+CSPR2tJB/BpVSX65rkau1VWDiR4=; b=Upy595PGrtRKmV5MlyOBG+dKGk LkeBkt4h8N5XttWb9k8dUfifYGvQzseZ9E/rC+RH6C6DrQCzRsUDPW4ZVIdCNv8e xItX774qlmRCq9KLGKeePzhoJHwgutwBmuOBvK6M9Iooh/Y5YMkzMpzGHG/AmGyP 0fTk6M6ZiUILdcEqjbiF8BMK6qmXfKThDiUrRsGfCDpieGa/lavCifXGxVsAIWAI QjZNXuwxybLKBSk0Ih5a3njDjLpZ+XphyV1NZaBUoKHqBZJ8tOEMjdijSVh8kZXD rVRIFhJmtgkBSfa97xK8ua+kobO/rehWHoTzSoeaQcCSNGxB0XhETCXhLBTA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162723; x=1724249123; bh=bAkMX/B++S8eeyt+CSPR2tJB/BpV SX65rkau1VWDiR4=; b=FJcOHGLS03bMyLp1bPUBHscCfqBx3+hZ9mndXJxvBaeW mznuocYV8EbOJHhjtT6ln+kNbgCNu99qRF3AZZcqWTZQahCPEhGQloOVchQL7GVI n02vVpG9vaBhpTG4521qVWUHovD/Tdk6Cbb5hm/SKdWCBMpuA1o5SwOqZwWeqnq2 eF1srX9vRAMZbMiU1nAV6ONvVPTrEWv3D6O4Cljd0dREcqMQ7chNACF9b6WSwbbr p9JkRE6QDnuszQ4hwAjI80fbYpT167hTaaxwD+6/KM/8JDe5UVml38q4QIkWC2hE AzknjsUyDoHJKWT5gDv8TQ/uHLBn2eyV6ozfN2OU1w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:22 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 637a47ba (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:04:50 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:20 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 07/20] builtin/archive: fix leaking `OPT_FILENAME()` value Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The "--output" switch is an `OPT_FILENAME()` option, which allocates memory when specified by the user. But while we free the string when executed without the "--remote" switch, we don't otherwise because we return via a separate exit path that doesn't know to free it. Fix this by creating a common exit path. Signed-off-by: Patrick Steinhardt --- builtin/archive.c | 7 +++++-- t/t5000-tar-tree.sh | 1 + t/t5003-archive-zip.sh | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/builtin/archive.c b/builtin/archive.c index b50981504f3..63f02990d11 100644 --- a/builtin/archive.c +++ b/builtin/archive.c @@ -100,13 +100,16 @@ int cmd_archive(int argc, const char **argv, const char *prefix) if (output) create_output_file(output); - if (remote) - return run_remote_archiver(argc, argv, remote, exec, output); + if (remote) { + ret = run_remote_archiver(argc, argv, remote, exec, output); + goto out; + } setvbuf(stderr, NULL, _IOLBF, BUFSIZ); ret = write_archive(argc, argv, prefix, the_repository, output, 0); +out: free(output); return ret; } diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 72b8d0ff02e..7abba8a4b20 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -25,6 +25,7 @@ commit id embedding: ' TEST_CREATE_REPO_NO_TEMPLATE=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh SUBSTFORMAT=%H%n diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh index 961c6aac256..01f591c99b9 100755 --- a/t/t5003-archive-zip.sh +++ b/t/t5003-archive-zip.sh @@ -3,6 +3,7 @@ test_description='git archive --format=zip test' TEST_CREATE_REPO_NO_TEMPLATE=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh SUBSTFORMAT=%H%n From patchwork Tue Aug 20 14:05:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770154 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 1F62B192B7F for ; Tue, 20 Aug 2024 14:05:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162728; cv=none; b=sASyDd7qeKbQzf1pwSA45g4fPJ5xd0yn5u0pnSLGHmvdvqzc04kj9Y5c227PXLVvPwyAzeujdcIHQsn5l6gXynq8WHXcV9NP0kpqy7i4fBxMWjFeaj9PF3L3aO/pzHKykmfPXzNys5VXtbGxcWG/wtE+9rckZ+UGrH/SmUwZ3Ic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162728; c=relaxed/simple; bh=vDxiqRp6iVYwbpu0j3aIDA5HytQKw8+cQrVg5vTFAsk=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Kj+vd8t0A9PJ5Qulcl6mW8CzbKEg6wi/no0HUdEd4D8QyID700yI2LrdZ1NGKRGSuGf4UBMhqV6EzEede05xyJ+nMpeIm70M6N53kocuokj/8gn5PgT8Jn/vCpQq9p+ATp+eOmgpVGGeOyvFuvKSBX80TBUMWAGkjzORy/UzK2U= 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=UeAJ/oB3; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=AVxok8cT; arc=none smtp.client-ip=103.168.172.148 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="UeAJ/oB3"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="AVxok8cT" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 401ED138FC62 for ; Tue, 20 Aug 2024 10:05:26 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 20 Aug 2024 10:05:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162726; x=1724249126; bh=4ADS7qcSFd 9ayjtKurewjD8k2fjjnnkXYWgV7sEV1YU=; b=UeAJ/oB38j4h60vOShyL1+hEco UTlBJ6mkzkOTz+46ld2/7ixvR/JQAzdiilI6YF8/hV34q+kLj6inNsuzBRkRgysy BXrSUX6yBf/uFurf7XnLGdW6Fp1Q+WOwhGtogCunDt43c8u8aECarhpC97KT/w2X 4APpV2+HURh71ZT/HncQcvqEOIJ0+nvMKtRhjenQiR2Cz+7S27HMRU7hYAPgr9AO FgGBxtw+nQkL9lKJqjqPsdSxaAQDO51BTGfoUu1wcN/6Ppc5CRKWaBvnaJpJ/3jX 6NXagrMw7d6gU0J480VppsIwgnykVXGj1cE+BVbAKq0QTewbPkziaItGbiIQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162726; x=1724249126; bh=4ADS7qcSFd9ayjtKurewjD8k2fjj nnkXYWgV7sEV1YU=; b=AVxok8cT2cuvUVDndXi4fegYTD7k2+ZYif9g0U9RroQf ascYJybtO5pkd8OTR3fOrvJTQkILt0ZO5eAIANApDjz9JJZx0oX0SStuEfB6kG0e KI97ipoLRzWvh51bj6SnTtMX4rjUYBju57S98SZ1lXzGQ85CRHqhPpHtIoo6iiQv k8QhBmVCvPLwsqTFvtcXaJ+vayQRVsHuhPLdErZHy6uDE4xNT85MzmH6LxrndkdL 8S/Xz4n+JsjYpbumBejaSyAHu2ks3y+4+LBvjwsjKJ7BjBkoppH35yC/WxevTO+R wA6Kwjn7x1DOx0Nvx77ri3ML32b/lycCwdg09ydNIg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepgeenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:25 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f8176d8a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:04:54 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:23 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 08/20] midx-write: fix leaking hashfile on error cases Message-ID: <5f042ce5098563aa0662026006c356c278dad0b8.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When writing the MIDX file we first create the `struct hashfile` used to write the trailer hash, and then afterwards we verify whether we can actually write the MIDX in the first place. When we decide that we can't, this leads to a memory leak because we never free the hash file contents. We could fix this by freeing the hashfile on the exit path. There is a better option though: we can simply move the checks for the error condition earlier. As there is no early exit between creating the hashfile and finalizing it anymore this is sufficient to fix the memory leak. Signed-off-by: Patrick Steinhardt --- midx-write.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/midx-write.c b/midx-write.c index e3fa33203fa..07d98d494aa 100644 --- a/midx-write.c +++ b/midx-write.c @@ -1308,6 +1308,18 @@ static int write_midx_internal(const char *object_dir, pack_name_concat_len += MIDX_CHUNK_ALIGNMENT - (pack_name_concat_len % MIDX_CHUNK_ALIGNMENT); + if (ctx.nr - dropped_packs == 0) { + error(_("no pack files to index.")); + result = 1; + goto cleanup; + } + + if (!ctx.entries_nr) { + if (flags & MIDX_WRITE_BITMAP) + warning(_("refusing to write multi-pack .bitmap without any objects")); + flags &= ~(MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP); + } + if (ctx.incremental) { struct strbuf lock_name = STRBUF_INIT; @@ -1333,18 +1345,6 @@ static int write_midx_internal(const char *object_dir, f = hashfd(get_lock_file_fd(&lk), get_lock_file_path(&lk)); } - if (ctx.nr - dropped_packs == 0) { - error(_("no pack files to index.")); - result = 1; - goto cleanup; - } - - if (!ctx.entries_nr) { - if (flags & MIDX_WRITE_BITMAP) - warning(_("refusing to write multi-pack .bitmap without any objects")); - flags &= ~(MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP); - } - cf = init_chunkfile(f); add_chunk(cf, MIDX_CHUNKID_PACKNAMES, pack_name_concat_len, From patchwork Tue Aug 20 14:05:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770155 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 E0068192B7F for ; Tue, 20 Aug 2024 14:05:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162732; cv=none; b=PJYsU6uV3rnpoq0O1G8mZ+iQYmdVreqtaepkDgJsNUWzKHOYouLHmKVVopHsSU6LPoqiS4XVDRw3VwGLLS8WA5XPyQ2Jhs8ApXEWUmPcqphJ3VdaLceuSol6UCh4UI6qNeXGJh5qjPZV0uwIJ0mNOf/svkzBbtKrPGAmvHi3kPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162732; c=relaxed/simple; bh=DEea8iumaiIyTjdVibVHbZDBXPo2P26lnOzw+eVBliw=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Y8baXhVcX2sfHutvgWMaMigMzvcslP/JgXtRwW2PkIbO0D/rSvamFtopnFrsqJV2KbU8QQrwBiqPNGxO8fnp9KNB6jxWA4K81aLAnw/xID5QboZXIiiif6l7UZY3FY0zqaCWr/3hgXC7bczfFpb1uWXhiCFb0qtHEVNrAQeJ6q4= 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=HQC8tb0M; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PFEH/H8z; arc=none smtp.client-ip=103.168.172.159 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="HQC8tb0M"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PFEH/H8z" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 6DBBB1151A9A for ; Tue, 20 Aug 2024 10:05:28 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 20 Aug 2024 10:05:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162728; x=1724249128; bh=TBKopDpBE3 gNhl9eJ/7zC7QF/PLppGWTdOdaR3zQNxY=; b=HQC8tb0MCe7f8BlUugplUIlrFg zmuFNg+0XFKGW9zyL3x1ZH/ZpTPFOitJJSffxKBCYVPKcfbjL4i6EKClvITj4OOy W06vLDxweQFpeHafdZ2hYzWL92B6qisUjhk+TRBW6h2U2qqR3IeDflnekYCKvx30 /gO2KpsDXHZqlkVcFhXrgjJW9BNR5htkDD9B2lrdemxzDbFf4ieVuGOt/rxiB3d7 LZeVgsLfVNsnPZRcu/j4YxTYD26MthWJwQWuyS4GupSc3cjflH2v/POGLtUhR44W bC2SHKeCyuA0zSAowD/VzIojguVGn0mypRk++cA/cp+W4Irk9/MUj10utjgw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162728; x=1724249128; bh=TBKopDpBE3gNhl9eJ/7zC7QF/PLp pGWTdOdaR3zQNxY=; b=PFEH/H8zI4nZBKPdlhXtI+s+95H+FMLvu2W27SySs03L ZPdgGn1cHgQ3T3/GQM6iT+I0IAKPPSEwUKwO7n+NhYL84OCTI+TxFQf6WGix9q5R 38rjtaOZy43o93P+WsYR5FpZV78Q7wpnrdUWx8BkLbQehLqlqvmPgCBF2MGdKTXL MPOMPA7sS+KOWF6HCwssnVEJSjjL4YA2E3IgGjmkCCA6ClmHNcAqrFnlyyAuoP5B Aa3rVvHPpB+BzVpWWBffZhNiRGX4GX6lC3J6IVrVGbXk/my2pCBPr3fseBBJitgJ rw+O7by6P1nDKc6/txEA/moi6XJdM1tLqhcqXQ4Ycg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepgeenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ab98c092 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:04:56 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:26 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 09/20] builtin/repack: fix leaks when computing packs to repack Message-ID: <5c820da97616466dd903f35981033a4fbf431dbc.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When writing an MIDX in git-repack(1) we first collect all the pack names that we want to add to it in a string list. This list is marked as `NODUP`, which indicates that it will neither duplicate nor own strings added to it. In `write_midx_included_packs()` we then `insert()` strings via `xstrdup()` or `strbuf_detach()`, but the resulting strings will not be owned by anything and thus leak. Fix this issue by marking the list as `DUP` and using a local buffer to compute the pack names. This leak is hit in t5319, but plugging it is not sufficient to make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- builtin/repack.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/builtin/repack.c b/builtin/repack.c index 62cfa50c50f..8bb875532b4 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -732,14 +732,23 @@ static void midx_included_packs(struct string_list *include, struct pack_geometry *geometry) { struct string_list_item *item; + struct strbuf buf = STRBUF_INIT; + + for_each_string_list_item(item, &existing->kept_packs) { + strbuf_reset(&buf); + strbuf_addf(&buf, "%s.idx", item->string); + string_list_insert(include, buf.buf); + } + + for_each_string_list_item(item, names) { + strbuf_reset(&buf); + strbuf_addf(&buf, "pack-%s.idx", item->string); + string_list_insert(include, buf.buf); + } - for_each_string_list_item(item, &existing->kept_packs) - string_list_insert(include, xstrfmt("%s.idx", item->string)); - for_each_string_list_item(item, names) - string_list_insert(include, xstrfmt("pack-%s.idx", item->string)); if (geometry->split_factor) { - struct strbuf buf = STRBUF_INIT; uint32_t i; + for (i = geometry->split; i < geometry->pack_nr; i++) { struct packed_git *p = geometry->pack[i]; @@ -754,17 +763,21 @@ static void midx_included_packs(struct string_list *include, if (!p->pack_local) continue; + strbuf_reset(&buf); strbuf_addstr(&buf, pack_basename(p)); strbuf_strip_suffix(&buf, ".pack"); strbuf_addstr(&buf, ".idx"); - string_list_insert(include, strbuf_detach(&buf, NULL)); + string_list_insert(include, buf.buf); } } else { for_each_string_list_item(item, &existing->non_kept_packs) { if (pack_is_marked_for_deletion(item)) continue; - string_list_insert(include, xstrfmt("%s.idx", item->string)); + + strbuf_reset(&buf); + strbuf_addf(&buf, "%s.idx", item->string); + string_list_insert(include, buf.buf); } } @@ -784,8 +797,13 @@ static void midx_included_packs(struct string_list *include, */ if (pack_is_marked_for_deletion(item)) continue; - string_list_insert(include, xstrfmt("%s.idx", item->string)); + + strbuf_reset(&buf); + strbuf_addf(&buf, "%s.idx", item->string); + string_list_insert(include, buf.buf); } + + strbuf_release(&buf); } static int write_midx_included_packs(struct string_list *include, @@ -1476,7 +1494,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) mark_packs_for_deletion(&existing, &names); if (write_midx) { - struct string_list include = STRING_LIST_INIT_NODUP; + struct string_list include = STRING_LIST_INIT_DUP; midx_included_packs(&include, &existing, &names, &geometry); ret = write_midx_included_packs(&include, &geometry, &names, From patchwork Tue Aug 20 14:05:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770156 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 3A5CD1917EF for ; Tue, 20 Aug 2024 14:05:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162733; cv=none; b=adMDPxG7hjUKTHmFpv8Z+OJ+GQxWHpijZeSy8cpC3kcmlI4Gi26Zi+dERlTU5MzJ2OfOXvLVTLxB3KZ+8xHII8SqJab5ranRfvY/7OHv4Ig9ggJi/oNkbTTgl1GlWXsRsW09UHah30f3r6mjroqWUUN7PQfsaxWPWJSg1b4y604= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162733; c=relaxed/simple; bh=y8K1KjuELFVbwthYQp2OWFJiyd6MN6eKlIY3ZWYPOlo=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=vEBTcJ5EfdtVExuAIrzBM2LReWrudfLopDZf1FpXkUZe57+nwlkEuDmyPpbdFRqKjN+xUOm95UDh7qjhkMUTmCFyIRxu7TLjHPgjT90oRzJ9V/fQwLAFkV2iQKQJGsxV1N3sLwxfg9L5G5fdLsn03QNjilqhowhwjXt7u4t4+tY= 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=Xksxe0SH; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UEysfmNm; arc=none smtp.client-ip=103.168.172.148 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="Xksxe0SH"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UEysfmNm" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 592C3138FC36 for ; Tue, 20 Aug 2024 10:05:31 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 20 Aug 2024 10:05:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162731; x=1724249131; bh=O8QXy96Qtf R6mQErCqM+V1HmQQkJtD/I900UtsWbPr0=; b=Xksxe0SHvcq3jTL4L4pVj6bocB 301DBc2kZzNC4E5LZnSnGUvYNwUhJDhnW1jmKpEPXVoZRvbUjNp7GAuU+MFN5eQl AyfUOSboEKQ0OHbikAZXGEn2Rh09x9SPgQ8oNrkmjmBezKz2dmCh4t8+4o5Y1ILm L6IcNTD0W7dbYgSpcQlzjIjYXPQ978xsAdZHoSYWtVrSmcohDgcRAzlZU4nSH10o am1232kuEySj7Zwqx8MHExLG1Gg5sA6/oc6asHYkXVPPKMmLSMJGDCxJUQ1xYA3a jLgFoYZTmHPempqbgypLAFrfoRjy5vO9NuqYEf2LqOZdRXRamZuH2Ux9zt/w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162731; x=1724249131; bh=O8QXy96QtfR6mQErCqM+V1HmQQkJ tD/I900UtsWbPr0=; b=UEysfmNm9tDQC06iby/U0LRG4G3jYnXV8zl8oW6HI9RQ /jNCx8qsGrhI3o9EFxkSOz2BPokLPRz/AYQ6AabNx51VurlH/ursW9AWuR0UqbEL fObE45yiOeJXdwtM2BYYIoZcyQBwOskW+eJzhnFAx7LK1WIajCyaGFuvfDguvgys CcCyNEGzkrfOHjonMaM6pTv9DR7WmY70/Dh/R7wqtWWAEDM9nwIk+p4wpbeeDD+P jC8NZatenIx4BfYWrGiZKmlsv1Z+HKKLCcL4yw/lwHDjJ4BA7IbMbr5+G6xdnyOF /xsNdPDlxHLoHy49OVXfInZSEN4RWvIOxnpP7gg8Cg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepieenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:30 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7ab3b4eb (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:04:59 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:28 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 10/20] t/helper: fix leaking multi-pack-indices in "read-midx" Message-ID: <9caf5eeea934da49608420fa09fc9179c73a4de7.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Several of the subcommands of `test-helper read-midx` do not close the MIDX that they have opened, leading to memory leaks. Fix those. Signed-off-by: Patrick Steinhardt --- t/helper/test-read-midx.c | 8 +++++++- t/t5319-multi-pack-index.sh | 2 ++ t/t7704-repack-cruft.sh | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c index 69757e94fc2..438fb9fc619 100644 --- a/t/helper/test-read-midx.c +++ b/t/helper/test-read-midx.c @@ -86,6 +86,8 @@ static int read_midx_checksum(const char *object_dir) if (!m) return 1; printf("%s\n", hash_to_hex(get_midx_checksum(m))); + + close_midx(m); return 0; } @@ -102,10 +104,12 @@ static int read_midx_preferred_pack(const char *object_dir) if (midx_preferred_pack(midx, &preferred_pack) < 0) { warning(_("could not determine MIDX preferred pack")); + close_midx(midx); return 1; } printf("%s\n", midx->pack_names[preferred_pack]); + close_midx(midx); return 0; } @@ -122,8 +126,10 @@ static int read_midx_bitmapped_packs(const char *object_dir) return 1; for (i = 0; i < midx->num_packs + midx->num_packs_in_base; i++) { - if (nth_bitmapped_pack(the_repository, midx, &pack, i) < 0) + if (nth_bitmapped_pack(the_repository, midx, &pack, i) < 0) { + close_midx(midx); return 1; + } printf("%s\n", pack_basename(pack.p)); printf(" bitmap_pos: %"PRIuMAX"\n", (uintmax_t)pack.bitmap_pos); diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index ce1b58c7323..fbbc218d04a 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='multi-pack-indexes' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-chunk.sh . "$TEST_DIRECTORY"/lib-midx.sh diff --git a/t/t7704-repack-cruft.sh b/t/t7704-repack-cruft.sh index 959e6e26488..5db9f4e10f7 100755 --- a/t/t7704-repack-cruft.sh +++ b/t/t7704-repack-cruft.sh @@ -2,6 +2,7 @@ test_description='git repack works correctly' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh objdir=.git/objects From patchwork Tue Aug 20 14:05:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770157 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 41A0D192B7F for ; Tue, 20 Aug 2024 14:05:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162735; cv=none; b=MrmrDy/9922bo0w4pjEJ6aM/A6C+ymx+NECOt7P1VmBpEp6wzDAv6AujMl0N6v8JZ/39UsF+FBrjyRR4J9IgIRffO0fdvGRuJbViRW/H+5B93YvfNldEGwvrwQfB9Welf4/irqbm9BsRLfD4k3bcGdg5oDhgdoLFmsusggleolk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162735; c=relaxed/simple; bh=frzfgQegaiMTWqYDcpcJFAN6SevmLupG95bK/iyYZMU=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BVrYFV1UGE59P9I2q1da94Vgu/LM2D3OvZwWOzwhoGkv8SI4uZFmoAcq76EhBlwRV3baIemQqHk8c8vgttYqeb4dZHtTel4gC+rt92KH9dRyjGgF5Fsx6cDWLmNdOPZ1osdRvr165rHncEsG1MKrtdo4q5UMGXCju4aCOCvvW9E= 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=jzHZgOsg; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ng1GFSvk; arc=none smtp.client-ip=103.168.172.159 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="jzHZgOsg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ng1GFSvk" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 335E11151A82 for ; Tue, 20 Aug 2024 10:05:33 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Tue, 20 Aug 2024 10:05:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162733; x=1724249133; bh=vXKoifygpu jg1nDhlKxsTPXskdygzLtZUauu5641c+8=; b=jzHZgOsgzUMkZ7xsog9RaoET8D 6iyubOpfaeZfFR+OpI069K7P7u+/WpQyCtL9vamLKmPfsrJ4tC1BZcy3bNDp84UT vpuRTx3ZB91RDljGNzL3DgZ5X2G2x/I4n/ONKx1/1Vi/xO/axpwmSaL0unzMWhNx SUV3rnTXlbLRon24qLmJAdsN5oIe6am/nNPblA6mUgdq7vSFvDpLfY88fsrhKYxV 0gwwX9jXMSZGLwLs1SYvQDiFLK/hqg6g+oleu287E97EmCdfrIMhQ817R4U+4aC0 kBRgcLIc5D27s6treu/EZci/IYY5fNvp1rDgdDl2BiVbvAzINsV1j8ZBRKug== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162733; x=1724249133; bh=vXKoifygpujg1nDhlKxsTPXskdyg zLtZUauu5641c+8=; b=Ng1GFSvk8dd7+/kjL2XZtiqt+3vNNyiRuVdNEOiJIn9V 5HPSF/E+tI4wWG4N3okZrlqHi3CG66H44N3bIav5yAsJz/hZdaIp96xe+Qc8/9Vt 0//ubQ98VC4bTGoJpa5tpBrPPCaK39bnkQ3d5jKYBjaK5ZGfAxyZnhQEjoDI2Kex kamaclWuMByHSGayW0OIqIl+jeIxlGJeYqAvVC5eayDRKY+UsPkyaJefNdZTeUVx SBV0WykDAfRdI7fCUWJbFmTWnkTjNl8Zyvn7PBRLIStROaiPvfCw23FNE/7Giqjp aWNpnNQso6fNmpfbvPWdTeMegYpWdYFdb74jeFM84A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:32 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7965b5de (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:05:02 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:31 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 11/20] transport: fix leaking OID arrays in git:// transport data Message-ID: <8e12c55536d8de52f5c5a972c739977b69d624ce.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The transport data for the "git://" protocol contains two OID arrays that we never free, creating a memory leak. Plug them. Signed-off-by: Patrick Steinhardt --- t/t5501-fetch-push-alternates.sh | 1 + t/t5519-push-alternates.sh | 1 + transport.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/t/t5501-fetch-push-alternates.sh b/t/t5501-fetch-push-alternates.sh index 66f19a4ef2b..0c8668a1b8e 100755 --- a/t/t5501-fetch-push-alternates.sh +++ b/t/t5501-fetch-push-alternates.sh @@ -4,6 +4,7 @@ test_description='fetch/push involving alternates' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh count_objects () { diff --git a/t/t5519-push-alternates.sh b/t/t5519-push-alternates.sh index 20ba604dfde..72e97b15fab 100755 --- a/t/t5519-push-alternates.sh +++ b/t/t5519-push-alternates.sh @@ -5,6 +5,7 @@ test_description='push to a repository that borrows from elsewhere' 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 ' diff --git a/transport.c b/transport.c index 7c4af9f56f2..f0672fdc505 100644 --- a/transport.c +++ b/transport.c @@ -946,6 +946,8 @@ static int disconnect_git(struct transport *transport) } list_objects_filter_release(&data->options.filter_options); + oid_array_clear(&data->extra_have); + oid_array_clear(&data->shallow); free(data); return 0; } From patchwork Tue Aug 20 14:05:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770158 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 57C8D43AB2 for ; Tue, 20 Aug 2024 14:05:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162743; cv=none; b=UQ31CT5bGdYtxxIobp3Vn0Mj7kFWbbx5gzKJy8f0guxPTEp7vx/YbIQWfSNqNYvyJXNn5TNx9JfKDzVKcdjZWviZTnvo2RE2NW39npzR2Tbn7O8wgk1r0+DB2v37JDHY3nXhOIGUvCcENj+ZR8y1T0oWXJJleLydEJCjoXnlMwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162743; c=relaxed/simple; bh=C5cwareO0W7oYeLcgZkeCKuwuCjDCFyEOhsDpvAgKxI=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sV/oGVWZElRmwRozZmLuJES7foCOFBing+T8YfL2o2KrIqiNzIqeZWrcDTIrVmTr8DG6eQApR7LKvcZV1//LGoCEbl0EppVfkpqzFImDuJ+0NAKZr2SOzkgbn4ftDra/W022XjbVp0CcKShPeSr9NeinKOU8aV6X8rie3pZOrkE= 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=ZNJgrPrn; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=evXBMWHF; arc=none smtp.client-ip=103.168.172.148 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="ZNJgrPrn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="evXBMWHF" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 77E48138FF1E for ; Tue, 20 Aug 2024 10:05:41 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 20 Aug 2024 10:05:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162741; x=1724249141; bh=8MsbH4+FTr HtG/Xv2YoGxlTRjel4tAHFGdg9PDQNSMg=; b=ZNJgrPrnuth6YkfurjrCVTtME8 z/UM6gl2jbY5sQ8yxxh3LNAOyvgnHB0rsZcM0V+Tt/3tY/VtLVqoUprX8DOUDTnF TmGT7NdywBiI+FN5qNpdQ0ldsYSo4Iuivjqkot0GMw+JzGr4XrMB5lXttFhO+30W s6Q9WpyMzRMAQlGEdfWK0wZXkejOUcHuyM6KXZ5EOzAm1itmitNeQeHwEZ+BFhry LbndWZR9mgrSe5iGVcXdaENav2zlCeu3cVr0DnkwDG+p/ZK+6Z1KL7+0BrOqJ1ot hbYN2Q5qHc3jQL4JLs4EbE9mFyLgVyYCQzRPK4ZqJoyD3qx1IYndi6+6Hb4g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162741; x=1724249141; bh=8MsbH4+FTrHtG/Xv2YoGxlTRjel4 tAHFGdg9PDQNSMg=; b=evXBMWHFn5i0fxBpwJKEfA5BdUDdZSfweiY2zjdPw85i hh+s4alfOFaJc9FHSPePAtuahPkCPSuMxBSPWmohn3xw4GoXS33lUdmBpFFrHjwE ja+eRgjWIM0+xCUrCFJc+5IaIGVFK7VDjh3AlbKOScChNgXjgqXQCChJKtifr8Zw a9x8bsi199SqcqlLWIzuyPYrwxQtlIQCPqn+OeJ4iGj41Rcjt3UbFBLZM975NFT4 BOSW/Z1zRd1lCPFpuyaGYAEaXxumF9O8QvShUjJR9GlziK1EuL7sNIHb0F0HOdxs T9Y90LZ2a0N3Ti304DYEd9bt0sQkVJdVxaL4bmJcDg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepkeelhedtfeduie elveffteekhfefieeuvdegtdffiedvtdduueefveejffduieelnecuffhomhgrihhnpehh thhtphdrshhhpdhhthhtphgurdhshhenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedupdhm ohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrd horhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:40 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 901dc1b0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:05:09 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 12/20] builtin/send-pack: fix leaking refspecs Message-ID: <5d8e0a3d8b4c063d0c707a1bed8c692e6719c47f.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We never free data associated with the assembled refspec in git-send-pack(1), causing a memory leak. Fix this. Signed-off-by: Patrick Steinhardt --- builtin/send-pack.c | 1 + t/t5400-send-pack.sh | 1 + t/t5401-update-hooks.sh | 2 ++ t/t5408-send-pack-stdin.sh | 2 ++ t/t5548-push-porcelain.sh | 1 + t/t5812-proto-disable-http.sh | 2 ++ 6 files changed, 9 insertions(+) diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 17cae6bbbdf..ef0df808249 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -338,5 +338,6 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) free_refs(remote_refs); free_refs(local_refs); + refspec_clear(&rs); return ret; } diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh index 3f81f16e133..248c74d8ef2 100755 --- a/t/t5400-send-pack.sh +++ b/t/t5400-send-pack.sh @@ -9,6 +9,7 @@ test_description='See why rewinding head breaks send-pack GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cnt=64 diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh index d8cadeec733..3c1ea6086e7 100755 --- a/t/t5401-update-hooks.sh +++ b/t/t5401-update-hooks.sh @@ -4,6 +4,8 @@ # test_description='Test the update hook infrastructure.' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t5408-send-pack-stdin.sh b/t/t5408-send-pack-stdin.sh index e8737df6f95..c3695a4d4e3 100755 --- a/t/t5408-send-pack-stdin.sh +++ b/t/t5408-send-pack-stdin.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='send-pack --stdin tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh create_ref () { diff --git a/t/t5548-push-porcelain.sh b/t/t5548-push-porcelain.sh index 6282728eaf3..ecb3877aa4b 100755 --- a/t/t5548-push-porcelain.sh +++ b/t/t5548-push-porcelain.sh @@ -4,6 +4,7 @@ # test_description='Test git push porcelain output' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Create commits in and assign each commit's oid to shell variables diff --git a/t/t5812-proto-disable-http.sh b/t/t5812-proto-disable-http.sh index 769c717e88b..f69959c64ca 100755 --- a/t/t5812-proto-disable-http.sh +++ b/t/t5812-proto-disable-http.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test disabling of git-over-http in clone/fetch' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-proto-disable.sh" . "$TEST_DIRECTORY/lib-httpd.sh" From patchwork Tue Aug 20 14:05:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770159 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 AB390191F6D for ; Tue, 20 Aug 2024 14:05:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162746; cv=none; b=lRk0du2cqclbATtGKaY16HRLjwd53QK6n7yyDvrXD+x2iF0aHVGUA3ZoxaqrFtykX5fL+ojBJUbHFE2WJT5gG46lCAPZyrGLwc471By+gVyZfmGUAwiGV+0p1WsQZzwg8DGDtC0w7kzZ4YEEavJ/g4rbKTQpwvPt91MgmRlNQIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162746; c=relaxed/simple; bh=eowiTkLzdfTLy9KuGhwXGUGGY+unWvi17iYZP3vx+AI=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kcLCkIFFHvtqIHsOR6Y4aI7SfsSc/0pTFLubN7phifRcdt9RmsET5v54U5NII6VSXKY/eOiBSTi21XpgXzFncP18A9JkwI9Vh0W1ZrlGi+ddoaFvJ0+un7gQWkEgC9qVgfzBPoi8ZkKRd2dBOID9YbgoDqWHH5lhaWVcxBrDiTU= 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=gzeGYYg2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eLjP4vAe; arc=none smtp.client-ip=103.168.172.148 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="gzeGYYg2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eLjP4vAe" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id C14FE138D263 for ; Tue, 20 Aug 2024 10:05:43 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 20 Aug 2024 10:05:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162743; x=1724249143; bh=VpZD48IYH/ iZ5avU+FtTy+iY4+9OcKX3DOr/5Hgxg98=; b=gzeGYYg2I/yBoDbob/vtfSi+Ec TRww75DFA5G1XwQAsCBr7i7OS/hanajMlAlyZHiPBwuRx4LrIjiB30k6pZTJlowe FZwRvB0btsOigLvFth5Oxjw2n/NiBQdNCAyZfi0hzYJpF/JAkF6nP+2JmN0jpAgk IhlZBCUbmkO5pDc+edsfj/7alnplJ3iZJ/tnUyJofync6Ye6jvtbwPqDRnJlwjzb RA8GsrddShciB7LzmhhiO9bjoS/eMxTUyZdFNrRvlFsN9CYWLUu/MB7nZhnVKBk2 Gd4SoXZv4bo3MUrcifH+6t1s52jIlN4B16d8NScocaoGtpxoCpOHfRge6hMQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162743; x=1724249143; bh=VpZD48IYH/iZ5avU+FtTy+iY4+9O cKX3DOr/5Hgxg98=; b=eLjP4vAe6UAY34V2oh71HHkqiLziTlo8sKnRDo9rh26W NvVMlmjEovFRhGSeQXHF8u27EDzUnBjRPRhJytuAjv96ehcli+TzPw+qZRS0O+na AIrQ5K/bGUSQ1kTvPAYCmSAdh4uwHbtkbTi2SU4id9ZGqQxT7XR9KIvMzQvLiT89 8W6e92OFQvhFDsSogCjHYFuB1Gf1rexTfQjwvTj+84wUBSZPf25D8uUCiZIknbsV VCq4/oZ0cwtxquUKjkDShP+8oyiAFSO4lu8Z/PHTc+x4KboK7d39M8Ki3vdN+0ie jlWVOr4fx0U8LjHEUdKSMsu22UCrmP+MDIET2BSxvg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepjeenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:42 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a056732a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:05:12 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:41 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 13/20] sideband: fix leaks when configuring sideband colors Message-ID: <5d09959b6426e53a68e1bce547f9507bdf21bcde.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We read a bunch of configs in `use_sideband_colors()` to configure the colors that Git should use. We never free the strings read from the config though, causing memory leaks. Fix those. Signed-off-by: Patrick Steinhardt --- sideband.c | 8 +++++--- t/t5409-colorize-remote-messages.sh | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sideband.c b/sideband.c index 5d8907151fe..deb6ec0a8b7 100644 --- a/sideband.c +++ b/sideband.c @@ -30,7 +30,7 @@ static int use_sideband_colors(void) const char *key = "color.remote"; struct strbuf sb = STRBUF_INIT; - char *value; + char *value = NULL; int i; if (use_sideband_colors_cached >= 0) @@ -43,15 +43,17 @@ static int use_sideband_colors(void) } else { use_sideband_colors_cached = GIT_COLOR_AUTO; } + FREE_AND_NULL(value); for (i = 0; i < ARRAY_SIZE(keywords); i++) { strbuf_reset(&sb); strbuf_addf(&sb, "%s.%s", key, keywords[i].keyword); if (git_config_get_string(sb.buf, &value)) continue; - if (color_parse(value, keywords[i].color)) - continue; + color_parse(value, keywords[i].color); + FREE_AND_NULL(value); } + strbuf_release(&sb); return use_sideband_colors_cached; } diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh index fa5de4500a4..516b22fd963 100755 --- a/t/t5409-colorize-remote-messages.sh +++ b/t/t5409-colorize-remote-messages.sh @@ -2,6 +2,7 @@ test_description='remote messages are colorized on the client' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' From patchwork Tue Aug 20 14:05:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770160 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 98045191F8C for ; Tue, 20 Aug 2024 14:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162749; cv=none; b=HV1OENJW/1TBBugOOXmTc9Mh1tEH/1XoIbdLNJrvAc6JKn0kUHeOBmk9fBvcoIzN6NSnM0HlJv6GOs3WIscJ0i5LuBGd3v1fcxiNci2sBGe6q9bB4E0g6pJNS8Sd7QnxjkAyCTxCM6Ka+XxvGsMTtF3EmPc078QfTT1iPbXw8OU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162749; c=relaxed/simple; bh=9wQt4BHiI/bt4NyKITEtRjgp3D8b62VJEnSMyDCYMkQ=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=j3RV6Cwl0R/L6lJbT2YhUAS1OEK/XItLwlw2DBjXcukdSYnbPaeAU7NATVQz0jDJyg7AUQWFV5lLu0Oj+PnxZqVa+sw/JXJZx6ieLRo3SLUkatymNQG99ikbh/A3RV+p24U4AaAEi5lhU2ytLB+MD/iBKf6ozIwhPoEjJn8rMQM= 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=HSPgQyJA; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=DYeYbBWH; arc=none smtp.client-ip=103.168.172.148 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="HSPgQyJA"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="DYeYbBWH" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id ABB5E138FC5F for ; Tue, 20 Aug 2024 10:05:46 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Tue, 20 Aug 2024 10:05:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162746; x=1724249146; bh=jJaGu/U2tT ESezbyhYQIMT3CF0nv9IjwY5IFbxYDrss=; b=HSPgQyJARPkd8BbZZokc2dcGkk e+55LbvP9FAZtu9F5uOuLjpIn+GukK87Bh4z1XwZpgwyjGg3h/IWSdwR05vV6e4n fa22MdijOR7Fg4zGsgahl+Q1wGgni9HUOWIO5gkk3c89QfB11208okX3ZJauU0n+ P4IxUqxH6g0TbXTjn3CZgdr7kOqqs/tAQzfa59WolNNssD+J4b9hjv79UBxnCA2T N6NOlOqFomMUIUgwvOyx+ExwxL1E6RbhJzVUldvQtYLTdtbCdrisangXUJAO/5vW 4FfWxUhUbZRS8dwhLcj5NW651nHjaRVWggalmgrjOt6jHiATy3ec8fYuQYfw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162746; x=1724249146; bh=jJaGu/U2tTESezbyhYQIMT3CF0nv 9IjwY5IFbxYDrss=; b=DYeYbBWHo79BatZFbgTm+gdMIPZJPW15ItYtbn2jh6D5 M5vrELki/gWIxh6q4cilFtuKcAx4JUTJA4pRh1+oRqh0zxGuSF//UpahEW/d/yOG LNsFgSabqJYlb3V2tOqPDPQpj3ZLFmJ4kbkz1IuDNEKy7dQ4ccT3LgLGchbtyh0A jr0Ruqx/9HhdtMVXuvsq7jnH1TtrwZXY09U1n8NJ/4T0HNIxs+rn5tffEKWF1GOC xUmHYtvF6plvSbU4rS6hdcvZegLfr8n0RA8zkhtH8i9ImNHnMKLHRK/y55ORKicY 7T38uvjfMuhYgVRrxW30taMBE0NExdaz1wzHi0nh5A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:45 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3d80dbe4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:05:14 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:44 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 14/20] builtin/fetch-pack: fix leaking refs Message-ID: <1c94195488d2db8ba169368a6c28171d5a2640f3.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We build several ref lists in git-fetch-pack(1), but never free them. Fix those leaks. Signed-off-by: Patrick Steinhardt --- builtin/fetch-pack.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index af329e8d5cf..fe404d1305b 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -46,7 +46,7 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc, int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED) { int i, ret; - struct ref *ref = NULL; + struct ref *fetched_refs = NULL, *remote_refs = NULL; const char *dest = NULL; struct ref **sought = NULL; int nr_sought = 0, alloc_sought = 0; @@ -228,19 +228,20 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED) version = discover_version(&reader); switch (version) { case protocol_v2: - get_remote_refs(fd[1], &reader, &ref, 0, NULL, NULL, + get_remote_refs(fd[1], &reader, &remote_refs, 0, NULL, NULL, args.stateless_rpc); break; case protocol_v1: case protocol_v0: - get_remote_heads(&reader, &ref, 0, NULL, &shallow); + get_remote_heads(&reader, &remote_refs, 0, NULL, &shallow); break; case protocol_unknown_version: BUG("unknown protocol version"); } - ref = fetch_pack(&args, fd, ref, sought, nr_sought, + fetched_refs = fetch_pack(&args, fd, remote_refs, sought, nr_sought, &shallow, pack_lockfiles_ptr, version); + if (pack_lockfiles.nr) { int i; @@ -260,7 +261,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED) if (finish_connect(conn)) return 1; - ret = !ref; + ret = !fetched_refs; /* * If the heads to pull were given, we should have consumed @@ -270,11 +271,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED) */ ret |= report_unmatched_refs(sought, nr_sought); - while (ref) { + for (struct ref *ref = fetched_refs; ref; ref = ref->next) printf("%s %s\n", oid_to_hex(&ref->old_oid), ref->name); - ref = ref->next; - } + for (size_t i = 0; i < nr_sought; i++) + free_one_ref(sought[i]); + free(sought); + free_refs(fetched_refs); + free_refs(remote_refs); return ret; } From patchwork Tue Aug 20 14:05:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770161 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 9CD94191F93 for ; Tue, 20 Aug 2024 14:05:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162751; cv=none; b=GctIY9hrWecoaI2E42SNyQZRkpDd6tPAkdyISPVSiEyeVy3OP7gdIkdKepSsXehu7ihkbexiPOCCNTgyUytCcDVQLza2P7BVBA8vcfKdeK6nIfk6QwwCS9yWLhSWOYZMnP2NnjIRLxzo7bpEDZ7qoePEc7e8rDEME9duhYiWFG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162751; c=relaxed/simple; bh=rYAzZils8BVEcOYEI0Ik86E9n8o0S6azlAkc8069t/A=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PxMEvr8uWtHOgSBcpx1ahKDxz7oh/3rXP+7yRA4gf1RuM3H99nF78MeXNnkQ2OfeVre2PRsY7VQJG5Rsfo1O/itKOTHYfdpk7oiZRqA7ngU5otWbFRvfMyPiHMbgc0frhxsh7JNFEp0JGiKejU2TyEnvnLjox50WbB+xtB6FGL0= 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=lyamy9d4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PTbBZNkZ; arc=none smtp.client-ip=103.168.172.159 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="lyamy9d4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PTbBZNkZ" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A9BED11518E8 for ; Tue, 20 Aug 2024 10:05:48 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 20 Aug 2024 10:05:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162748; x=1724249148; bh=o4P9rnbq2R /rUtNpkv2BX9WZhluxON/m5nDMV5n+KLY=; b=lyamy9d4GnFsJjBiYgiv6Qv4c3 yt4kW2w6Ort/9Up2hMDhfAKTOLb+wUK3Gxe/JuFqP2JsSXb2eTSbJxK+ICis1X9j XuAc/Opt2rFcy2lv5gwPANG8XdpzVcOOfNgOyQ1fQ70nTFPVgdkJho2d/HV4ifI3 1iJaut+jrO9L5ZEJidKOjHKs5DJ9r5ygjh4CS6It4G8+e0puWqSWI2e2FdBuoR/6 IsM0FLENNYydPnjQT6cnJTa663Sq/4OGyqUEtzSaAxExyAoC+tVfYCsLRagT9Z32 2GwRRLkhIlTMvUMKPZDyZlj+xoKyMxvgM8NsYhDY1XbSZWGMSa+bt4cmdVeA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162748; x=1724249148; bh=o4P9rnbq2R/rUtNpkv2BX9WZhlux ON/m5nDMV5n+KLY=; b=PTbBZNkZGkdYDyByd4V4md3SdiJUEGRj8vpLtXB/I24L fiVvtKRsyp+aHa3c84MmyyY72VcBT0zPn6/MTKeTLUB0HOkOJEFPZ/H26dT/qaOT p/qT1b/T4wBEr8hJtTTPdyg+vhlHn9YVyOdODJpEOwvSAWJH9u/644BoWlx/Nf4G ApYsmQUIdzbc1yMUqQgJYLI9RmmYEffaqAIdjKNzVYbnct/C04AhMCJMtuq16cFF xcmPWSIzUAo6xVlGjZAtUJjcswSKjlfk7daCoURnNX/FPFqBf+6bkmSYb+K8akp8 wrcXqIBRonev9wuOkckMn4TPhrginUpBvE084T8/+w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:47 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3a49173a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:05:17 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:46 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 15/20] remote: fix leaking config strings Message-ID: <97346d6f944e3587a08d96a5e1b4ead8df8a0bc0.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We're leaking several config strings when assembling remotes, either because we do not free preceding values in case a config was set multiple times, or because we do not free them when releasing the remote state. Plug those leaks. Signed-off-by: Patrick Steinhardt --- remote.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/remote.c b/remote.c index 7d5b8f750d8..3087437bc61 100644 --- a/remote.c +++ b/remote.c @@ -373,8 +373,10 @@ static int handle_config(const char *key, const char *value, return -1; branch = make_branch(remote_state, name, namelen); if (!strcmp(subkey, "remote")) { + FREE_AND_NULL(branch->remote_name); return git_config_string(&branch->remote_name, key, value); } else if (!strcmp(subkey, "pushremote")) { + FREE_AND_NULL(branch->pushremote_name); return git_config_string(&branch->pushremote_name, key, value); } else if (!strcmp(subkey, "merge")) { if (!value) @@ -406,9 +408,11 @@ static int handle_config(const char *key, const char *value, return 0; /* Handle remote.* variables */ - if (!name && !strcmp(subkey, "pushdefault")) + if (!name && !strcmp(subkey, "pushdefault")) { + FREE_AND_NULL(remote_state->pushremote_name); return git_config_string(&remote_state->pushremote_name, key, value); + } if (!name) return 0; @@ -475,12 +479,15 @@ static int handle_config(const char *key, const char *value, else if (!strcmp(value, "--tags")) remote->fetch_tags = 2; } else if (!strcmp(subkey, "proxy")) { + FREE_AND_NULL(remote->http_proxy); return git_config_string(&remote->http_proxy, key, value); } else if (!strcmp(subkey, "proxyauthmethod")) { + FREE_AND_NULL(remote->http_proxy_authmethod); return git_config_string(&remote->http_proxy_authmethod, key, value); } else if (!strcmp(subkey, "vcs")) { + FREE_AND_NULL(remote->foreign_vcs); return git_config_string(&remote->foreign_vcs, key, value); } return 0; @@ -2802,6 +2809,7 @@ void remote_state_clear(struct remote_state *remote_state) for (i = 0; i < remote_state->remotes_nr; i++) remote_clear(remote_state->remotes[i]); FREE_AND_NULL(remote_state->remotes); + FREE_AND_NULL(remote_state->pushremote_name); remote_state->remotes_alloc = 0; remote_state->remotes_nr = 0; From patchwork Tue Aug 20 14:05:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770162 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 C17F5191F93 for ; Tue, 20 Aug 2024 14:05:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162754; cv=none; b=QlhlY/oB2QE0I62pT2otedJamZyFnJnlhuJ/I7XLwZMR4oSXrgAgxQTfIEVBL7oTVoGRRMyMTGcURXwWSr6/rozt7RXTHHLaROu/PV5R7MYAlLBlovZPOT0iFQjFarTv4UsNBkmaJUYY0g8PbZc+BUJmi4jznTeWCtNp8GjOEes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162754; c=relaxed/simple; bh=4YaLenxutTXDO0GCcmYYXKk6xmPIl3FeLf+uCZ1skqs=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TFrpgEbz004vuRY4SXdliB01uDY2y/yI3TRs0RvKSfoMA9ESYeadC8nWBK4VUyYvEPqpsKQ8Jo5to/TJKbiHqsCUAJ4dhHSryl6vbyNKN98hf/EoOc6ojNhu03ZcqLIc4JhGCEZz9YC9QUpqadd+PkO3B47neajw4BAH34ftpvc= 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=Xig7HsoZ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=o2+wDXha; arc=none smtp.client-ip=103.168.172.159 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="Xig7HsoZ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="o2+wDXha" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id EDBB21151A9D for ; Tue, 20 Aug 2024 10:05:51 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 20 Aug 2024 10:05:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162751; x=1724249151; bh=7UCTuFodKX kWAuhrHXXY0naJs4oghahZmaAFfSNs6QM=; b=Xig7HsoZJD5Gkak8LHLk2FWZ+x ewCkq5STbmO+iNCZmQV56JyfjhyirhYXARbt9TOLsWf1+shtx61QqCU0sUG8P8/v 15hzwasphu5bomfjPNxtBcQbyZp3P0CMm2Gafel4mJRZ0jZpVQ2dfc1gIHRCPLBj 4+FAw2nETDvNHMV1J6e3aScwAXziEDkpS5bC8xJqLTQJ0eUJtRv0c47wHxKhChCq EzDnooZW0IlfpJG5Nh0aWEhqBnV69lkBUsz4HVWcnoNi05YZM0OdJHCxWzCA2AuA 0lWVUJk7YsnGf40zzfSHfh2ho8nx2G0VqmiNzCEqAdoLk0do2tO4S4OqgBkQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162751; x=1724249151; bh=7UCTuFodKXkWAuhrHXXY0naJs4og hahZmaAFfSNs6QM=; b=o2+wDXhaw5QaSwfwovZcF3jOOyib2n+o3tYfw4oFO+us h/aFuj3hdAtB/tfxAdcy/WRYKGvaEa5nyge1i0UURqFGtPWaY8iRTRREMjs862iH T4g/kFcb0m9zzY3DVfRqBSv/LtPszacepFBOuCeiU5oQ+Zag/GYbdgHCWVv6V4v7 6fGl7vIBsQiXgNNWGVAbSNOcJcDMu3n9g4gz6nFX12gvJeLb2lWvmz0DF2PfjfNA Gg6T916YV3Htdv5xoopTkJ2Q9gyqB0LCJFzM8DxcjgcLEsFTCx81XaLCCz0EHm/R iyjqb/z8LQJEJy2AewlIpjvE87cTfecNcLx8NY1nWQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepkeenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:50 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b04fdac8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:05:20 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:49 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 16/20] remote: fix leaks when matching refspecs Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In `match_explicit()`, we try to match a source ref with a destination ref according to a refspec item. This matching sometimes requires us to allocate a new source spec so that it looks like we expect. And while we in some end up assigning this allocated ref as `peer_ref`, which hands over ownership of it to the caller, in other cases we don't. We neither free it though, causing a memory leak. Fix the leak by creating a common exit path where we can easily free the source ref in case it is allocated and hasn't been handed over to the caller. Signed-off-by: Patrick Steinhardt --- remote.c | 43 +++++++++++++++++++++++++++++-------------- t/t5505-remote.sh | 1 + 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/remote.c b/remote.c index 3087437bc61..892a47086db 100644 --- a/remote.c +++ b/remote.c @@ -1325,18 +1325,21 @@ static int match_explicit(struct ref *src, struct ref *dst, struct ref ***dst_tail, struct refspec_item *rs) { - struct ref *matched_src, *matched_dst; - int allocated_src; + struct ref *matched_src = NULL, *matched_dst = NULL; + int allocated_src = 0, ret; const char *dst_value = rs->dst; char *dst_guess; - if (rs->pattern || rs->matching || rs->negative) - return 0; + if (rs->pattern || rs->matching || rs->negative) { + ret = 0; + goto out; + } - matched_src = matched_dst = NULL; - if (match_explicit_lhs(src, rs, &matched_src, &allocated_src) < 0) - return -1; + if (match_explicit_lhs(src, rs, &matched_src, &allocated_src) < 0) { + ret = -1; + goto out; + } if (!dst_value) { int flag; @@ -1375,18 +1378,30 @@ static int match_explicit(struct ref *src, struct ref *dst, dst_value); break; } - if (!matched_dst) - return -1; - if (matched_dst->peer_ref) - return error(_("dst ref %s receives from more than one src"), - matched_dst->name); - else { + + if (!matched_dst) { + ret = -1; + goto out; + } + + if (matched_dst->peer_ref) { + ret = error(_("dst ref %s receives from more than one src"), + matched_dst->name); + goto out; + } else { matched_dst->peer_ref = allocated_src ? matched_src : copy_ref(matched_src); matched_dst->force = rs->force; + matched_src = NULL; } - return 0; + + ret = 0; + +out: + if (allocated_src) + free_one_ref(matched_src); + return ret; } static int match_explicit_refs(struct ref *src, struct ref *dst, diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 08424e878e1..532035933f3 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -2,6 +2,7 @@ test_description='git remote porcelain-ish' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh setup_repository () { From patchwork Tue Aug 20 14:05:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770163 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 630A0191F93 for ; Tue, 20 Aug 2024 14:05:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162757; cv=none; b=uwgbmPwzutpmNly5EYewkXG1bLoaORAtvHD+55N6PA0zxy31njKZd/UubTIlxqiRpD4Qf8fNXpBlhK83wt5ozd9lKZxbUoFn5RU4RHHdFxLBMYkKX9A1yGDQyZ2ZXbFfkTwu4opLm1JA6QBPgRm08rL4JnU2Vy4M7uR+am6JV2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162757; c=relaxed/simple; bh=j0WEXaLLA5C/GnIjUA3mAXwSU5Wd8l4cEdYJOGhcOJE=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RdRJGZdV0LguSULRByIOLcUiIba4LJZquiDXUP2kULfzfXAPbLk00PHOcmSorLM+9Wgi864Igv4knKxhb2kTlxKsXBKC2CvedEYPPe5UuPNQvYCOuhkGdRn1GGEYjATMvaqXKZsZeVcfCSUsJXJ0Iz/84N2XkR3P9GJdxLkE9bQ= 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=pJfaFSqU; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=k43BORYb; arc=none smtp.client-ip=103.168.172.159 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="pJfaFSqU"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="k43BORYb" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id D9DD2114BEE1 for ; Tue, 20 Aug 2024 10:05:54 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Tue, 20 Aug 2024 10:05:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162754; x=1724249154; bh=FKLhRoExGG zleaqPxBTINQGg8KhL27hmoPCsao7mJk8=; b=pJfaFSqUPdUPS5400mHy749vmO HfUlwcyCiecntQKgv+702fX+SoLqFadt95P3A2cUnYoun+4BVFFmC7PRbHsRnUoR bM8qRXdmqOr28Qg2oqZcBNfDi1udF7ahQkuwWNVOlAFGs+7rON5IfTUK/IE8f5AY jsxr5qysgxV3xKT+mOQMojiPyCKAUp5rYYMT6rUq8Q8jc746jClrWDMqrREUPJEY DQW3kEc3q8WiOI0uHvHwawrDe0FuYArZobb2hIXRv+ndsbVUDiRbPEHtfPYEYrEx s0fS6QyskqbcXCh7hcUkwm45c3QhDSiH4K0NHLyOZpK4VCcG9r88IlaThZ8w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162754; x=1724249154; bh=FKLhRoExGGzleaqPxBTINQGg8KhL 27hmoPCsao7mJk8=; b=k43BORYbIfrFR0VEt1Gk76zTluDFUxfmJs/27UnnTVHX 6HY4Su+GM6DAiE6azAGP8X+xiFDVQWIubvvprFBcfsj2HePbSM8yFkCfsCz2XK0w NuXcS5limv7sWy+SDpTKj48rXbvjyhM+FDEfMyMcAuOVGYTTa0t4t0s+3SSOHWSG fQXffiNaqMh3nXsZXML5tWRN8ws07lwEc9APYk3vejn3R8IIt6Rl/ic1xXsODRbP iQeC96qT+SYOqdyCJZYdTK8qKpqZGlDNk7U3AO6Vqt1UnCL0SM2kCtmqmGt8BHQq Hx195+vAgThVwabPAzpEttggAFNAjuplCeQVQTbnKg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:54 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id fd3b0c82 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:05:22 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:52 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 17/20] remote: fix leaking peer ref when expanding refmap Message-ID: <773fe580d750e94e34499f385701794eefbc9c27.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When expanding remote refs via the refspec in `get_expanded_map()`, we first copy the remote ref and then override its peer ref with the expanded name. This may cause a memory leak though in case the peer ref is already set, as this field is being copied by `copy_ref()`, as well. Fix the leak by freeing the peer ref before we re-assign the field. Signed-off-by: Patrick Steinhardt --- remote.c | 2 ++ t/t5536-fetch-conflicts.sh | 1 + t/t5553-set-upstream.sh | 1 + t/t5703-upload-pack-ref-in-want.sh | 1 + t/t6050-replace.sh | 1 + 5 files changed, 6 insertions(+) diff --git a/remote.c b/remote.c index 892a47086db..6b50cafbbd3 100644 --- a/remote.c +++ b/remote.c @@ -2062,6 +2062,8 @@ static struct ref *get_expanded_map(const struct ref *remote_refs, !ignore_symref_update(expn_name, &scratch)) { struct ref *cpy = copy_ref(ref); + if (cpy->peer_ref) + free_one_ref(cpy->peer_ref); cpy->peer_ref = alloc_ref(expn_name); if (refspec->force) cpy->peer_ref->force = 1; diff --git a/t/t5536-fetch-conflicts.sh b/t/t5536-fetch-conflicts.sh index 23bf6961700..2dcbe790523 100755 --- a/t/t5536-fetch-conflicts.sh +++ b/t/t5536-fetch-conflicts.sh @@ -2,6 +2,7 @@ test_description='fetch handles conflicting refspecs correctly' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh D=$(pwd) diff --git a/t/t5553-set-upstream.sh b/t/t5553-set-upstream.sh index 70e3376d31b..33e919a17e1 100755 --- a/t/t5553-set-upstream.sh +++ b/t/t5553-set-upstream.sh @@ -4,6 +4,7 @@ test_description='"git fetch/pull --set-upstream" basic tests.' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check_config () { diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 191097171bc..f75fae52c83 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -2,6 +2,7 @@ test_description='upload-pack ref-in-want' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh get_actual_refs () { diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index c6e9b33e44e..d7702fc7562 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -7,6 +7,7 @@ test_description='Tests replace refs functionality' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-gpg.sh" From patchwork Tue Aug 20 14:05:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770164 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 02F24191F93 for ; Tue, 20 Aug 2024 14:06:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162762; cv=none; b=L7IFLw2bruv1N8FUOMGyJB2+YDgAVoFhiHfngSkDmkB4M+m0hLd+tXBtLHfsfnpXy96LgcOFx7YNgCxrYe2UnQL+PxThMSTaYS/A/NzwYb0JokVfdFytM18CtmxdxF9eIYtawTlNWePCq/bxBL+p1QYr9sceHJD6YP2FGpLbWRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162762; c=relaxed/simple; bh=QLPG/ImQs2pcRSbXlKo57qxLPs1KHvNODyorTa4JRDI=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WhfrFD1anJPrZeSyUDyUZ1s3rlC3ckFi7VOBHzuWsbZno3wVqIFAuSPpq6Z5+V4o2h/bsESwmSUr1PD+tClA9udrvuZcHn6n6q+Mo8kaSYXW+1abEJyGpAbK1T3cbcMHBRHBkrVyd2L8/N4JVOucTg/v/bFA19nmGoC500ya2rU= 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=ZuxuswhE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ovbl+AVN; arc=none smtp.client-ip=103.168.172.159 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="ZuxuswhE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ovbl+AVN" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id D48051151A9E for ; Tue, 20 Aug 2024 10:05:59 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 20 Aug 2024 10:05:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162759; x=1724249159; bh=LmZRIKtX9a uGvNsTj8OGDyx1pMfRoPXBFiMIdsEFrXY=; b=ZuxuswhEDHKrXANTKcJ7IHUYsi 65CJAc1Oe8KZ/FH6RCkbOU2u0VSpaAq52v/JyzETJfy/USEsmSHILh4B91/uHjB1 jHGwCEBKDX2ORvsQHJxIiP29Fl+niaWeLP0dtaSEhmjILvLiGEQJ5vo0yFPYfoKg qqktJEGujFGBO0mcgBpWrfBLEkCpuWISWfjwPX2R4rK78QVha9qRevKIqsn90oqP iBvuzvBURWIKG2YZqZqsAs0L8oQbwjAOnJxHJVc0U2tVbgt88oN+SLQ7fCbSU4sU CMgdr2VTkxx7YK2AvnEBf4aiKQKq9Y5gtHEIMyLiZYoXaqVibXK3femsuDLA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162759; x=1724249159; bh=LmZRIKtX9auGvNsTj8OGDyx1pMfR oPXBFiMIdsEFrXY=; b=Ovbl+AVNTr6iAA+yl41cKDS4QOJDbiTDjS9IjA02KBw0 i6tGndnFKUvc7QAd/H+WXXfUeRwJyhVv012GvqEiZBZzqR+jrhX9RskYYeFdXWlb AIni5I8MiyRQtW6Y2zHKxMlKg3zn7+iUgrYgrnK5ktAXH3CksV3sd5g7VbZGn09n brMbw3vd0CBJPTBoBxLf6j3VuZ4BC41HVh7n6kbQXM7D/c6OPMahu1u80d7FjmM8 zAkG08C2GnNRcnLl4WQ3aKu4sWvVrA9ShnJHePgloN1vKMubmv0GqyK55+SCdzee y9g2xwuxS9M3KjfNWcUys8vKr4LvjOZHp3TW6vqMRw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:05:59 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a2108e09 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:05:27 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:54 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 18/20] builtin/fetch: fix leaking transaction with `--atomic` Message-ID: <9ede792550e0b289d931c7f0fcf467873f09c5a5.1724159575.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: With the `--atomic` flag, we use a single ref transaction to commit all ref updates in git-fetch(1). The lifetime of transactions is somewhat weird: while `ref_transaction_abort()` will free the transaction, a call to `ref_transaction_commit()` won't. We thus have to manually free the transaction in the successful case. Adapt the code to free the transaction in the exit path to plug the resulting memory leak. As `ref_transaction_abort()` already freed the transaction for us, we have to unset the transaction when we hit that code path to not cause a double free. Signed-off-by: Patrick Steinhardt --- builtin/fetch.c | 8 ++++---- t/t5574-fetch-output.sh | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index c297569a473..0264483c0e5 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1731,11 +1731,8 @@ static int do_fetch(struct transport *transport, goto cleanup; retcode = ref_transaction_commit(transaction, &err); - if (retcode) { - ref_transaction_free(transaction); - transaction = NULL; + if (retcode) goto cleanup; - } } commit_fetch_head(&fetch_head); @@ -1803,8 +1800,11 @@ static int do_fetch(struct transport *transport, if (transaction && ref_transaction_abort(transaction, &err) && err.len) error("%s", err.buf); + transaction = NULL; } + if (transaction) + ref_transaction_free(transaction); display_state_release(&display_state); close_fetch_head(&fetch_head); strbuf_release(&err); diff --git a/t/t5574-fetch-output.sh b/t/t5574-fetch-output.sh index 5883839a04e..f7707326ea1 100755 --- a/t/t5574-fetch-output.sh +++ b/t/t5574-fetch-output.sh @@ -5,6 +5,7 @@ test_description='git fetch output format' 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 'fetch with invalid output format configuration' ' From patchwork Tue Aug 20 14:05:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770165 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 83B111922CD for ; Tue, 20 Aug 2024 14:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162763; cv=none; b=pr8Il4vdBU3bItM6TSMrOYoyjdm1viY8ymXKPnH66cUjQGTRdaUdEqvRoeiKMIsMN3rpGJBhL4C85lubPvNyw/bHW9SFuibRzFe5M1Ts//GVi64t/PMfVuinKjf/Cv4nL/NyOs5qou2fhKjlogcsq8PcUUDAvhmzUX3WUEsEn14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162763; c=relaxed/simple; bh=bclwHcx7huN5h1iyclJy2PECO3tLbMMKUAsR0KtdcLI=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eastRCUIJhYeN+knh+4DG6ppE9k+biz6qi7N6UfEg9uXwYn/fxg/9L6bDzv0mAee6C36avP/1jlm3lYvJsiP5LYFHL/ElbFkzoGBePRpzHwQYB1bsH4q+w93DO3e6Y0Gzs1E539VdE7oTn5NiT0qD5FOmBoAe5KTxpufTHhDuaU= 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=MMN61gml; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kIU6I9Eu; arc=none smtp.client-ip=103.168.172.148 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="MMN61gml"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kIU6I9Eu" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id DFADF138FC5F for ; Tue, 20 Aug 2024 10:06:01 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 20 Aug 2024 10:06:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162761; x=1724249161; bh=doiCI79cEh SpG7JmnFypy0mdIJQscTnHKAcvZ+VcjRg=; b=MMN61gmlUYi5HBERM7uoTT8raB zKUZJ6jR6qZUJMUi4WMhSSxgoSIllv+ev/QAXYUCzy4An4Dxuc6ax2lku+EwqWKQ NBHp3aA6zvC8mq3vLYJqDbXtQYCBmR0TMIUbSoCRsuaRLCJu9yK8dZ2fBRW3Ymdd B0iAz+JtgWR6maVtDaWJY9l0tBguTOO2vWvTPhVm4tpb1PIWIzMK3vFRqNim9Ksa wvIetb5fQLF+7QlbP2zBxL96fw+fbUCrLUh8bT6Gj1mREcrrgZ+A6/LHN+01B+AJ lic+U45BSZwo3yaniOrezeoAxP/nZp+FuPDCmX3toB5r32iZ+2wn5i+q96+w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162761; x=1724249161; bh=doiCI79cEhSpG7JmnFypy0mdIJQs cTnHKAcvZ+VcjRg=; b=kIU6I9Eu2HkZJgYjaywWiiweRr68Gay3YVsLYmkX/Nk2 CiEefaVDuZhQ/lSPRIs+c/VoPI3RDykZ3Oi0iSPS4WaR5kifUMRAl6+pHlE2uSLU 4WV53tO+0FfhyjfOdtbmf431OhvfBY6kh0JGPa9fn1Uoi/WKwx68A2vjQB06OBQR ViOUq0yNtwwiK5KMe8soc2kamOdI4VxYcACgYMQtk8XkArEoykG/HOCKtJfHt00g mwG0/DG6T3XGRFJTkZEwh06fOvUkIqKiHEjyw2NHVPiI51supFGU3vko+zxgbJdN QUj7WOrYP1FtusLVfMsHvcJyffZzQ5l1X8CqRn+5wg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:06:01 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f9bfcdff (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:05:30 +0000 (UTC) Date: Tue, 20 Aug 2024 16:05:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 19/20] transport: fix leaking arguments when fetching from bundle Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In `fetch_refs_from_bundle()` we assemble a vector of arguments to pass to `unbundle()`, but never free it. Fix this leak. This memory leak gets hit in t5510, but fixing it isn't sufficient to make the whole test suite pass. Signed-off-by: Patrick Steinhardt --- transport.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/transport.c b/transport.c index f0672fdc505..da639d3bff0 100644 --- a/transport.c +++ b/transport.c @@ -189,6 +189,8 @@ static int fetch_refs_from_bundle(struct transport *transport, &extra_index_pack_args, fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0); transport->hash_algo = data->header.hash_algo; + + strvec_clear(&extra_index_pack_args); return ret; } From patchwork Tue Aug 20 14:06:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13770166 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 84A471922E5 for ; Tue, 20 Aug 2024 14:06:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162766; cv=none; b=rA6f9KQF83SdPLgq96p7wtUvLSyJS57m7+l8zfHFMyn5Rc9bp+ErJTRw9l3hhKXNqzD8NXhl5xUI/mdN9GMyrrdF+v5jy34i7kplLbFX2f/KclkemexNegFHEKJFeYBNC9F9stUCoPPkzFXl4wgrxkwP2GO6XHeb3wqbE7yv69Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724162766; c=relaxed/simple; bh=zwg0kB4Rcsb8XD2nW8KQ2yJ+gZvuwV/Z3iVedjkkw2c=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hV+q2x7lrCFWRVIsXSg7qwO8bE7epRgRl6HEbqwhPyaTKFLX5oaCVn0fjwI2HrCHD2qdyPWpLmKaQyQZfMhTIdtRqNbCsTvvAkHNxWD6OXNubuUlELMdhdIf46f1VtllEBlfvryz+3woBE2I0XazAVZmrdKaeIx3xAd7khdtiMQ= 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=Bw1i+sPg; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=OByAkbkS; arc=none smtp.client-ip=103.168.172.148 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="Bw1i+sPg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="OByAkbkS" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id D5427138FC5F for ; Tue, 20 Aug 2024 10:06:04 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 20 Aug 2024 10:06:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :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=1724162764; x=1724249164; bh=Fx58xHcaAV XHT+2XgotGrdn2miPfx3kVxV8MC6HNayM=; b=Bw1i+sPgQnaIBLkYdf06TYHxtD eU0eGIflxdhX4kPeRcHqBY+9RokEIVTr3MngY0N2XVKeRuGYkn98uMFbNJ/OaEMO c13l1NB2/gW/CkMTr3kMnP1P0JJ5u8O5fA7GZYM3t8RQ8PsyqtZ7pJ58dFw3S8Fy EEQGX6rZAZmB2zCHHEIsBazlSQQmxTtCXHhpdZAGMVT/pMO2aWVgJBq2/3Wz3h6C 8w4UjIg3e/6WQW4vZ8qX3LKBIYAnA6Roilvg3rho9NvqXzDEq6DVcJj/zfs2mJ8I uLHpgYM2qdzuMlesIgiCacj1zw9X050sO0t8HaoIV/L9Aewo1d9xsmUoWqFw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724162764; x=1724249164; bh=Fx58xHcaAVXHT+2XgotGrdn2miPf x3kVxV8MC6HNayM=; b=OByAkbkSoUp1HwEc5trYELCPiNAMY5Mz7npv/klEg7qN gKD2+KgYgXOmpS+OtKhiT9UlnUBHsbnDqsVV0vylra0cnbSwFRPxKUtn722DK8VV GKDu1hTRod55BTcY7TmIeNLtfN3p8U6Rv8afcvxoCrB1ib5MCaeb2v9Fvyxi5Guj D7oLZPXr4QehNEKV8eRNLIgscGJhSUbuXsGI5vJ9cyXaw+ihafGsWsekg2ydG6E+ S53ZHE5S/PYmTUDPVyY3EXoy9hUmaUtddLe+uXfTntYPtEnYtIWoUEf6Fo6ozfq1 Zr3xwDcfF0l3BzgoNvhy/xhUSHt+KYx5MXTFHNTG3Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduiedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuf fkfhggtggujgesthdtredttddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhh rghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepheekfeefgeegvd egvdeffeehtedttdffjeeuffelgffgheefleffleejvdefheeinecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspg hrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhg vghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 20 Aug 2024 10:06:04 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 36d54ccc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Aug 2024 14:05:32 +0000 (UTC) Date: Tue, 20 Aug 2024 16:06:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 20/20] transport: fix leaking negotiation tips Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We do not free negotiation tips in the transport's smart options. Fix this by freeing them on disconnect. Signed-off-by: Patrick Steinhardt --- t/t5510-fetch.sh | 1 + transport.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 3b3991ab867..0890b9f61c5 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -5,6 +5,7 @@ test_description='Per branch config variables affects "git fetch". ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-bundle.sh diff --git a/transport.c b/transport.c index da639d3bff0..0f20fc56e40 100644 --- a/transport.c +++ b/transport.c @@ -947,6 +947,10 @@ static int disconnect_git(struct transport *transport) finish_connect(data->conn); } + if (data->options.negotiation_tips) { + oid_array_clear(data->options.negotiation_tips); + free(data->options.negotiation_tips); + } list_objects_filter_release(&data->options.filter_options); oid_array_clear(&data->extra_have); oid_array_clear(&data->shallow);