From patchwork Mon Jun 3 09:47: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: 13683534 Received: from wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (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 CECF585627 for ; Mon, 3 Jun 2024 09:47:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717408027; cv=none; b=Mq/CMKm77xGpjAJ8PQ87T1wVnaIiJWqqSjc1o+SdRZT1LdaveRxf/iyTqU6OaXiai7+gpW4OtZvVnhnLM6VasyKR/x4FgW2eG4F5i6qxYFJZO9oHycL5nKEzZ86jVb9DHo5YLzp+ipJrXgPTqPJAkw9CUdtUHpXFJwgHWTcjdGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717408027; c=relaxed/simple; bh=OD0FPgdsDZ7iZimdSELKs/7Jj8YDEwxIhuiIWIPE/D0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DBtMYNMr1IEKQrQFtD9+1yyNpuf+Yg/aoHKf9fX+VJ42+SLjriYlH2cykn7cegTLa9Hk9ifkKUyfjHkypji6SV/Pjf+khfrMXXONNDW3SL2kDQ0MlAwTjCYIFwSgTyE8NAoxuLggibsNorRZM8y8Ftp1Bt9gy41BrF7GH/qGykY= 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=F62s2mVi; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bt29kAtN; arc=none smtp.client-ip=64.147.123.158 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="F62s2mVi"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bt29kAtN" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id 2D9771800099 for ; Mon, 3 Jun 2024 05:47:05 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 03 Jun 2024 05:47:05 -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=1717408024; x=1717494424; bh=iE7d7C5POo pTDGuejXmACHRwwhrZikZpyNP9exvYWCk=; b=F62s2mViIxutdNhJD4ZzRXEwQQ wqCcsXWXJLs053OLEUHfr7uQMSOHhFwkMJ3MmhKfV+fcBnVv3exExxUY5Fdm1Vmv W8awHy1CoPPuBC8h8LTb6ruZjt3xOx6+AcDtzIQ3sZuFn4QGinNaH2n8AvMNfnme sMwgDkYJ1XeJlw+rriRdOWXtjqHHQaFaEocjy+SRo6spM2luZeRLBN4zLMxg27W4 I49AEGIiad2aJJ2ZwoC0mL5SU6Oq6WXPDjCEsHH4EITyaADMqvlAnvQxddw4PFBb gXl15Id1kBDCV5/5OCX8Cpr8V3yyHHDGdNbi3pp8eell36IZmZ9qiNPZ5qFw== 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=1717408024; x=1717494424; bh=iE7d7C5POopTDGuejXmACHRwwhrZ ikZpyNP9exvYWCk=; b=bt29kAtNXoxsasyPOkYRZQ8K3+Z6kGHBhbcSivi5BgLA zeXh/UQXy/91IuiAcy5J43J5zQFMKteR/i1QpJsg/5DR8V8KkR+SyqqtD2f/TI1K 69rqd9YR+yN6jxmrslTcLmVWsCLaY5YbAu7fhc4UWNeyrRlS4FMCsO4oYBqzd4yH NeKlFRoz0ebmNugZZkI6AASgM3RhAsQLwhddr7obPQJLGKVPKZEQWHWU90+ytXUq Qj2CqZbjbi/8qrUHZIMELEMX2V5MGiS7Q+EsksQKRYuB8vbJfFjQkQyWzunqThN7 GaQb2C99Bo9tRoxD+wvSZQAOJoj75cxeM3xGHxHLVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelvddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 3 Jun 2024 05:47:04 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 31c8a8a9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 3 Jun 2024 09:46:40 +0000 (UTC) Date: Mon, 3 Jun 2024 11:47:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 08/29] notes: fix memory leak when pruning notes Message-ID: <17671dc9cfbf51e091575241565fb1460a498a7b.1717402439.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 `prune_notes()` we first store the notes that are to be deleted in a local list, and then iterate through that list to delete those notes one by one. We never free the list though and thus leak its memory. Fix this. Signed-off-by: Patrick Steinhardt --- notes.c | 7 ++++++- t/t3306-notes-prune.sh | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/notes.c b/notes.c index 6a157e34ce..244b5c4b1c 100644 --- a/notes.c +++ b/notes.c @@ -1219,11 +1219,16 @@ void prune_notes(struct notes_tree *t, int flags) for_each_note(t, 0, prune_notes_helper, &l); while (l) { + struct note_delete_list *next; + if (flags & NOTES_PRUNE_VERBOSE) printf("%s\n", hash_to_hex(l->sha1)); if (!(flags & NOTES_PRUNE_DRYRUN)) remove_note(t, l->sha1); - l = l->next; + + next = l->next; + free(l); + l = next; } } diff --git a/t/t3306-notes-prune.sh b/t/t3306-notes-prune.sh index 8f4102ff9e..b6e9f643e3 100755 --- a/t/t3306-notes-prune.sh +++ b/t/t3306-notes-prune.sh @@ -2,6 +2,7 @@ test_description='Test git notes prune' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup: create a few commits with notes' '