From patchwork Thu Aug 1 10:38:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750127 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C352183CA1 for ; Thu, 1 Aug 2024 10:38:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508702; cv=none; b=Y/C++mdBzS7tuDqbLM/k1n/V5ZW1WqcC8EFOq93gd50anfxi11C4zf7icNqYrH4wZaKT0XpI41MpyNpdsEnc4labspzn9jzj670dyjAM446K8WWcjQrxbz6rGTR9ZhDE0Fen4+opQ4UAzh9RI9yGfAPbt8NdnTaEpB/W0sOvlz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508702; c=relaxed/simple; bh=yHS9K62Nug1YbfKBYBS4yeyS8Yo8q+FJcoQJ4xeyV3M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fz1tBQB5kHcdBJqMjDITAovDxE9r8aTNFqqWz6RThjf6dmmxgp8lN8Qc7+h82ouUlJBUjSm7HM09W7t+MVq3KwoDY42P5M2A8oaaRlyJGemjEIP5SGQvZqOX32LpHXfQuspf01UR/RMsFHWmleCKQ3zYT0YvtyuY2DP2Km4cW/w= 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=f8Fecv8M; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XqqNp4kv; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="f8Fecv8M"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XqqNp4kv" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 48555114AAF5; Thu, 1 Aug 2024 06:38:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 01 Aug 2024 06:38:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm3; t=1722508700; x=1722595100; bh=WRRGVyXesf +M5j2PC7ycoWJkg5Y7DN9FbUpWcjEr5vM=; b=f8Fecv8M0kZHvBECMb0AwraErY QEsm3j6yTG5gwnC1MigducqqOUAyCXVyUwR5pSEZqdgbOk/Cah4rplFrxbDDf33n H1zSGpBYaAOdPm0W0W/4Jru8fQ+IPWRuJSCegaaZtNaZnjnX9ZsPjS4xoE2+Maml 6NZeXRd8Bqavhd0FMDcV2WcmDLoFU7lTq2SQXEkGCPYBNOv3lYD5ATcOskSnPNV1 05dUZ3Oazf/8fq364rAPA+8fPx+ovSDcXiwmRmWWY1cvX5Qp+L8Q1gHrYKgFcDfJ OjDcMPGbsYfYkSyUB4KLsDyaMiR8Su52zkInR6p0jbaDHO29rGv6dYKkBtnw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm3; t=1722508700; x=1722595100; bh=WRRGVyXesf+M5j2PC7ycoWJkg5Y7 DN9FbUpWcjEr5vM=; b=XqqNp4kv5tOlhjcpN+/vXo0bT1usmy+ow9onwH/zncRA inkpfzAf6ZtMeOVU2NvyyyTxmhXUPKiZGPCbKpbYclEkRi/eHmnE3CgzaPiazwvx JrAyzwY+AgwvjeEmd5/MMy14tlQCRxyIRKkVFPvNcW/qZPFlop8xS2VDtd0WGFFh YyQ4SCTrpbnVyK5Xb+JXkn0MpJE3AEM8eyPvSPkak8e0jy6rOxUZyVJFJfWC4wYB eKs4fBe7HBV07nfAoMsMU4vXkHHZW9SIwxZMiavxOofwyZT+eqFu+Zbv/Nz4sihL utGWukoj97R9GZKCyQcxGw8ez9RsTuGSEbOelqkJ0A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:38:19 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 3ab3f222 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:36:46 +0000 (UTC) Date: Thu, 1 Aug 2024 12:38:16 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Taylor Blau , Junio C Hamano , =?utf-8?b?UnViw6lu?= Justo Subject: [PATCH v2 02/24] builtin/log: fix leaking branch name when creating cover letters Message-ID: <73a16fff43ee36f497f3ea7377a68babd3b9d392.1722499961.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 calling `make_cover_letter()` without a branch name, we try to derive the branch name by calling `find_branch_name()`. But while this function returns an allocated string, we never free the result and thus have a memory leak. Fix this. Signed-off-by: Patrick Steinhardt --- builtin/log.c | 4 +++- t/t3206-range-diff.sh | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin/log.c b/builtin/log.c index 4d4b60caa7..a73a767606 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1434,6 +1434,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file, int need_8bit_cte = 0; struct pretty_print_context pp = {0}; struct commit *head = list[0]; + char *to_free = NULL; if (!cmit_fmt_is_mail(rev->commit_format)) die(_("cover letter needs email format")); @@ -1455,7 +1456,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file, } if (!branch_name) - branch_name = find_branch_name(rev); + branch_name = to_free = find_branch_name(rev); pp.fmt = CMIT_FMT_EMAIL; pp.date_mode.type = DATE_RFC2822; @@ -1466,6 +1467,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file, encoding, need_8bit_cte, cfg); fprintf(rev->diffopt.file, "%s\n", sb.buf); + free(to_free); free(pp.after_subject); strbuf_release(&sb); diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh index a767c3520e..973e20254b 100755 --- a/t/t3206-range-diff.sh +++ b/t/t3206-range-diff.sh @@ -5,6 +5,7 @@ test_description='range-diff tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Note that because of the range-diff's heuristics, test_commit does more