From patchwork Thu Aug 1 10:38:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750126 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 DA1FA170A37 for ; Thu, 1 Aug 2024 10:38:15 +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=1722508697; cv=none; b=QjyGk+xl6HHt32gNoH6jl1NGpFjPo95LE1lQj6zBcQjrLeiKgXPqOZdnRQnv4bmwemvRigqnTQ+FQn95vAjC4IHhLAmY8blzgGxeDtuW6howA0iefL7adI2nnmWBwVXdRoRMeJVNVRa7cb470dW60pnPlz98hFjXz+v/We67cUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508697; c=relaxed/simple; bh=XMo+CPb4WyYUIbe7xV9U1wLE/QNLl+SmBsjwyPTenXg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YygeVgRYVs+yZhBql3hpjzLp/BBgTLQf/z7KM1E/67t4c4SDFNHRFRHIT63boODppia2MdDxh/rkyK+9wbBSbWMEIpoaqVxV8RAPMkPutF/TNu0vCZj77uUvOFIlJ92CF+OnJKhjurRZAsUD99D3EiyUr7rztsD1dPrFEYCszlk= 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=VvAchu1p; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kZNcD4Fq; 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="VvAchu1p"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kZNcD4Fq" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id DACE31387A85; Thu, 1 Aug 2024 06:38:14 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 01 Aug 2024 06:38:14 -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=1722508694; x=1722595094; bh=VOnmKJ4VYp O7niPKNJn9ogghV1pawQJ7Kgxw6JlaSI8=; b=VvAchu1pdQrPoAZw7ZeK8+2X+M 9twythE2AftqaBBhZoqQvyWtZgR4APK7dPwBryTVIeHwO4y94CIZUtE3J5e3r7dI tWQrzVEvAahrOWIJkpBzWeYT2NM5urmvWVyKxP/qAkyHTuo0rBJKuGGyMJiVCKBD kIDGG2YYo8jy2duvjXVwYTqRco7R+vKYbrcRtfgLU66vQNZ4BiWAX3rPKsKM9pah ZWVPmPYBEYgaBOW4WMn0ZFt0t0iJXcVmo0MNwtKUE5hUg/lmu92D+G47BzVBkCZ+ pYmVB8FRuKgVQTWUf0EhwchrRpxT3Xm3Weep6Ecj8UmHZSLhSi43V1VmNYSw== 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=1722508694; x=1722595094; bh=VOnmKJ4VYpO7niPKNJn9ogghV1pa wQJ7Kgxw6JlaSI8=; b=kZNcD4Fq7stLzNAnpR84azVySUUuUaYD/5cfZrzYbeZZ N1hAfmOirjiNphShvV68XjoWsU4veQPQJFC8G/oAXgQYkXWYr5e7p5JJq1gA4t3M ceZ2gcLwZKpu80Tl+32TxsMBUjoqLR8/oDU9uXPqCvsXzRyGMxJACmyB5OrW7iGc VIcA0LW6CJ7wfVswvayAiGC3MPFpgbXOvSpyGfSqAZI0dArqqMxTK5ptlJ4J93Yw bWiZdg28N9kDjoRyNEzYRr0EjVWGZrvw3EEbh5NF+yA5JUP5QLAIeKZbSnWCjkeE +mBcsDuryh22HaQXNl81To/a8i1hlsCJija4i140yQ== 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:13 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 46ddb5fc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:36:42 +0000 (UTC) Date: Thu, 1 Aug 2024 12:38:11 +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 01/24] builtin/replay: plug leaking `advance_name` variable 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 `advance_name` variable can either contain a static string when parsed via the `--advance` command line option or it may be an allocated string when set via `determine_replay_mode()`. Because we cannot be sure whether it is allocated or not we just didn't free it at all, resulting in a memory leak. Split up the variables such that we can track the static and allocated strings separately and then free the allocated one to fix the memory leak. Signed-off-by: Patrick Steinhardt --- builtin/replay.c | 20 ++++++++++++++------ t/t3650-replay-basics.sh | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/builtin/replay.c b/builtin/replay.c index 0448326636..27b40eda98 100644 --- a/builtin/replay.c +++ b/builtin/replay.c @@ -151,7 +151,7 @@ static void get_ref_information(struct rev_cmdline_info *cmd_info, static void determine_replay_mode(struct rev_cmdline_info *cmd_info, const char *onto_name, - const char **advance_name, + char **advance_name, struct commit **onto, struct strset **update_refs) { @@ -174,6 +174,7 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info, *onto = peel_committish(*advance_name); if (repo_dwim_ref(the_repository, *advance_name, strlen(*advance_name), &oid, &fullname, 0) == 1) { + free(*advance_name); *advance_name = fullname; } else { die(_("argument to --advance must be a reference")); @@ -197,6 +198,7 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info, if (negative_refs_complete) { struct hashmap_iter iter; struct strmap_entry *entry; + const char *last_key = NULL; if (rinfo.negative_refexprs == 0) die(_("all positive revisions given must be references")); @@ -208,8 +210,11 @@ static void determine_replay_mode(struct rev_cmdline_info *cmd_info, /* Only one entry, but we have to loop to get it */ strset_for_each_entry(&rinfo.negative_refs, &iter, entry) { - *advance_name = entry->key; + last_key = entry->key; } + + free(*advance_name); + *advance_name = xstrdup_or_null(last_key); } else { /* positive_refs_complete */ if (rinfo.negative_refexprs > 1) die(_("cannot implicitly determine correct base for --onto")); @@ -271,7 +276,8 @@ static struct commit *pick_regular_commit(struct commit *pickme, int cmd_replay(int argc, const char **argv, const char *prefix) { - const char *advance_name = NULL; + const char *advance_name_opt = NULL; + char *advance_name = NULL; struct commit *onto = NULL; const char *onto_name = NULL; int contained = 0; @@ -292,7 +298,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix) NULL }; struct option replay_options[] = { - OPT_STRING(0, "advance", &advance_name, + OPT_STRING(0, "advance", &advance_name_opt, N_("branch"), N_("make replay advance given branch")), OPT_STRING(0, "onto", &onto_name, @@ -306,14 +312,15 @@ int cmd_replay(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, replay_options, replay_usage, PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT); - if (!onto_name && !advance_name) { + if (!onto_name && !advance_name_opt) { error(_("option --onto or --advance is mandatory")); usage_with_options(replay_usage, replay_options); } - if (advance_name && contained) + if (advance_name_opt && contained) die(_("options '%s' and '%s' cannot be used together"), "--advance", "--contained"); + advance_name = xstrdup_or_null(advance_name_opt); repo_init_revisions(the_repository, &revs, prefix); @@ -441,6 +448,7 @@ int cmd_replay(int argc, const char **argv, const char *prefix) cleanup: release_revisions(&revs); + free(advance_name); /* Return */ if (ret < 0) diff --git a/t/t3650-replay-basics.sh b/t/t3650-replay-basics.sh index 389670262e..12bd3db4cb 100755 --- a/t/t3650-replay-basics.sh +++ b/t/t3650-replay-basics.sh @@ -5,6 +5,7 @@ test_description='basic git replay tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh GIT_AUTHOR_NAME=author@name 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 From patchwork Thu Aug 1 10:38: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: 13750128 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 AC95A170A3D for ; Thu, 1 Aug 2024 10:38:25 +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=1722508707; cv=none; b=i0moePNeFGjYFxlBoGE/rSqlO5bh4sWhKsqNINew/Pk4LEuM/m19kWu/BtxXNwHXYiZK2wgjVt8J1o3DLyq5r18AK4gXpkBIF76f9p/tcJgjWLSgQCQoOyRYI9HWRuidUsxbpIs4guVffnpKELiYkyiWyrSxwgSpMglwBLhNYvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508707; c=relaxed/simple; bh=bfD5beWF8lH3TatkkMaFk2bj6mX5WPHFLwfSg+PhD6k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jCic3sB/hYq/IawCiIPinwszSGzUG/7sDa8mrlpVcjqoCgcP0WQGo8L98gwplrvSKAAxc2tMl1CqhxkHlE9mXvWNt7VgElnkdDmKbyPANQGh2K7iT775pWH7oCC54Fa3qhcnDm0UzVU+6Xcb1JYxTWJghmJBEDNY+038icZGZlo= 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=R9HoebvB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=U99yLaZ3; 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="R9HoebvB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="U99yLaZ3" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id AF0721388042; Thu, 1 Aug 2024 06:38:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 01 Aug 2024 06:38:24 -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=1722508704; x=1722595104; bh=igtUrbvTjX GG1aBNIproiBQPQsv779VhxdAQjYTIRLI=; b=R9HoebvBzVWqXweCSIkyLtPLAf jS6fUca6iUD1yWfC4Tdnmwd2QueHLgh2YcZTvqXHZCC1Mr22rINbXPVZhYRaCjyG L9Ka5hjz6zsK4vWmMEenDwveyabKE0v/y9X390vcXABvBoSaTgARQo9ncujwerxw zgoLXn0oFfUdQKBXa34aUp9ZvqhbH3wsjwAxc/UY9CLkuypQcFhdVWKwzquqLfcD w/B9uvxtYv74ZwNEUX8v3dD+Xob9DlZQ97SwuRp/24oIfQDZBSsy5AiX9QPW6WJF DjRTVHOerVl/9MxXnqhOwQ8zTm9N4E0kk2XKP0SgIaEl+btSPcMc90Mdz5Hg== 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=1722508704; x=1722595104; bh=igtUrbvTjXGG1aBNIproiBQPQsv7 79VhxdAQjYTIRLI=; b=U99yLaZ3eR9P4OpD+qGLTISGSI8y8N4ncm6e79Gf4QTu aM7Hvb++fd6yxh8ngAblG/VpOzaE5Wz4ZNKpKAUMHqDhOQxKmldolwTzpGHUvfwh UxqIA5WYI2Y7RLhVPE3RjWqD7a1Ds6H7jynN2PQIX9MHV6U/sy05rYQXHl4hAOPr lLdI1pLT1GNeVmOkXqdBKwrnYeJGFe+YZUXOlPl6gQoAMuX2TbVmdRNZ3mQeOv+0 9OxrXWOKIn2h7ZUBva1GMINQt/g3+Y5pOGbYjRr2EVL1lC7wcA/S3srkI3JC4ib5 1YtooJqjdF3NJC0UTTusEUi3rbdQ7mkN7TV+Tbq2xA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:38:23 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ef2fe2c0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:36:51 +0000 (UTC) Date: Thu, 1 Aug 2024 12:38:20 +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 03/24] builtin/describe: fix memory leak with `--contains=` Message-ID: <65027d13b75a684d60112b12019871342939f2d7.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 `git describe --contains=`, we end up invoking `cmd_name_rev()` with some munged argv array. This array may contain allocated strings and furthermore will likely be modified by the called function. This results in two memory leaks: - First, we leak the array that we use to assemble the arguments. - Second, we leak the allocated strings that we may have put into the array. Fix those leaks by creating a separate copy of the array that we can hand over to `cmd_name_rev()`. This allows us to free all strings contained in the `strvec`, as the original vector will not be modified anymore. Furthermore, free both the `strvec` and the copied array to fix the first memory leak. Signed-off-by: Patrick Steinhardt --- builtin/describe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/builtin/describe.c b/builtin/describe.c index cf8edc4222..739878db85 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -619,6 +619,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix) if (contains) { struct string_list_item *item; struct strvec args; + const char **argv_copy; + int ret; strvec_init(&args); strvec_pushl(&args, "name-rev", @@ -637,7 +639,21 @@ int cmd_describe(int argc, const char **argv, const char *prefix) strvec_pushv(&args, argv); else strvec_push(&args, "HEAD"); - return cmd_name_rev(args.nr, args.v, prefix); + + /* + * `cmd_name_rev()` modifies the array, so we'd leak its + * contained strings if we didn't do a copy here. + */ + ALLOC_ARRAY(argv_copy, args.nr + 1); + for (size_t i = 0; i < args.nr; i++) + argv_copy[i] = args.v[i]; + argv_copy[args.nr] = NULL; + + ret = cmd_name_rev(args.nr, argv_copy, prefix); + + strvec_clear(&args); + free(argv_copy); + return ret; } hashmap_init(&names, commit_name_neq, NULL, 0); From patchwork Thu Aug 1 10:38:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750129 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 0179F170A33 for ; Thu, 1 Aug 2024 10:38:29 +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=1722508711; cv=none; b=n82FqHw2JI2ohygnycn5Y/MKLO3KeYN4yLwGf0ESpyTuGxsCbItT8UXhwfsPTRJFoJKmYzYPyz/KVi+3fFuBa7TVgttuVrSqNyISFad54NZ/2jYyBIABtQys08T2xuOI340I5BXisky30C1HCY4wwJ94iIGrFig8jsGARJstYnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508711; c=relaxed/simple; bh=bFjPQb5B4ie9X601R9uGDxXWD16t4NJ+VHrnTJK0n3A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GfT61M0eb46v9ZysjOPDqqziru0dEO6lOVVUhvHgz/SPEAw0yBcolx6vNzj+JeNkXUMlvu2xq7pK/+6C5RRlsM76qCzlwlRbprLyB1iakYCZrNRXxJY87bJVQvq9yb/SiOnfn1OuWklndOPrhhVABg2ckW/hUDVhBoy0m/dDsoY= 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=J7XVQ72l; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FQn2io8b; 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="J7XVQ72l"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FQn2io8b" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 2351611482FD; Thu, 1 Aug 2024 06:38:29 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 01 Aug 2024 06:38:29 -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=1722508709; x=1722595109; bh=tq8yMYQ/rf ++b37g2JHXI/O2bOCGTG7BU+c/qmtPHnU=; b=J7XVQ72lkQkJu8oktGTy97O60H h86805fhgMgnLMXBPblAUflXpWgNytu3bnJ3QMuzkffDHc9lbWj4S/X5TmwdEzks ggGjzESdQLrWt99EXWFsWCrDCvqDyZJWfiYyzIeRvMLXymjSiJGFL2yv94oIjB1U Vm6/XhPYgZlFQ57CtclzKVorJl1eh/LaMMvvZca1F0b/6NXHigAFBKVqAf5koov2 tcQaSB/X0kgYT3EtkLZiEU1ixNLqivJBfDaTK8jCqKyzu9fFNUMZiztwms3oMTib Zz+GKa1OXXPcsXm5LD8yYoaCkJ4hTGdC3bBkl1ndLnj+0sD1PrMRLKeouUzw== 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=1722508709; x=1722595109; bh=tq8yMYQ/rf++b37g2JHXI/O2bOCG TG7BU+c/qmtPHnU=; b=FQn2io8bpOn8KPqo+nnuoouGNsAqoqGLYi+jIaJrWlhc NETv9V/Xn+kUTZ3GxBbYNCkbUVdeEeNZw+UgyB3KRXewXf3ixp2L+dcNqXboFoXY ZXVwKFm1Ijqj+E9BXZNeNGnajPb2KQDYziRFq1ztqgZ7u2RWBfSWciRFR57PE5dR vseTiySoOZlUhSYeUWfQGRmhaHqng7oh/XXjs+kXhI364YmwHmbBPbaMQs1O8bXC nOqbW+b8NzIQoa7eBl2pgS+qI3KPOZzy3LbnGfv87qkJiVqau+0bIk9BZSFVSNfs 2X2WApWUH75pMG8VWs2UqLDAcF4m1ZL042O7RN6UIA== 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:27 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id bec5e3b0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:36:56 +0000 (UTC) Date: Thu, 1 Aug 2024 12:38:25 +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 04/24] builtin/describe: fix leaking array when running diff-index Message-ID: <19ca97e33a352b540a27feae5302c2311b707f9c.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 running git-describe(1) with `--dirty`, we will set up a `struct rev_info` with arguments for git-diff-index(1). The way we assemble the arguments it causes two memory leaks though: - We never release the `struct strvec`. - `setup_revisions()` may end up removing some entries from the `strvec`, which we wouldn't free even if we released the struct. While we could plug those leaks, this is ultimately unnecessary as the arguments we pass are part of a static array anyway. So instead, refactor the code to drop the `struct strvec` and just pass this static array directly. Signed-off-by: Patrick Steinhardt --- builtin/describe.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/describe.c b/builtin/describe.c index 739878db85..2957ff7031 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -695,7 +695,6 @@ int cmd_describe(int argc, const char **argv, const char *prefix) } else if (dirty) { struct lock_file index_lock = LOCK_INIT; struct rev_info revs; - struct strvec args = STRVEC_INIT; int fd; setup_work_tree(); @@ -710,8 +709,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix) repo_update_index_if_able(the_repository, &index_lock); repo_init_revisions(the_repository, &revs, prefix); - strvec_pushv(&args, diff_index_args); - if (setup_revisions(args.nr, args.v, &revs, NULL) != 1) + + if (setup_revisions(ARRAY_SIZE(diff_index_args) - 1, + diff_index_args, &revs, NULL) != 1) BUG("malformed internal diff-index command line"); run_diff_index(&revs, 0); From patchwork Thu Aug 1 10:38:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750130 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 6C8DC170A33 for ; Thu, 1 Aug 2024 10:38:34 +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=1722508716; cv=none; b=TjWHicY9lL+pAlWeMgzohRzhkUmvhwdCl8QXWhQsBL9hl2zhSPOcY6yOUFZIJnF0En3JQ4H5Z3vdoWvbn0CnJqzyqiZZu45VcKRvn1VEKfu3z5imIzH97ZW6k3mlc0K143nKKAFNriRWpe1QUYHxdyiA29+oDMsJGkDRXG9HD4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508716; c=relaxed/simple; bh=uMXS4ZDGtRn2npjYLU1Hf6wryCrN6ryHqh68Znoss6c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O5uCbLAlIyZC6iI87ejQ58vsI4nmAFHFpgf958S4EahOl3JNPmAnhIrVa2xZz+yKFdkWGIJnJRxQuRR6sejX5OlLvF4il4gnsUgfYiK2dGH5iL3zt6ugxHs+CJja5H71s7M5SnBILZsA7u6eOXVBj+r7peJHvbecYFne05A2K5Y= 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=n74L809v; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=AUV/ENi6; 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="n74L809v"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="AUV/ENi6" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 8CB181388012; Thu, 1 Aug 2024 06:38:33 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 01 Aug 2024 06:38:33 -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=1722508713; x=1722595113; bh=WqQz/r8eUV G5acOxYvOKLNinczBnV7Jqpwj8zkTQ3Ec=; b=n74L809v2MXHcvSJibSWMxrd2s MJcMH58XMpCDCT0Ugg7it49q/fTWxiSTM/xNLrbBkNS7aoq/zyY2TCQsZlyhJzGB gIm62e+S9axM3i5gHT72rPJ8irO82o/FNlg8EDjzON5vAaj/8R6PdhHP9QExw4AO xnQASGoD4rLNrXzDxZMCl7zqJUNFh11ftyJz/MHbG6nkesqHlZPC8aah0pYC1meA TVVFjsco2VtksR1iOE2JvPIzSw/z3mz+qvUBBnIQGsUD80CrXe4BnH1bbgbOQ0f8 TgqBVY86yckzdk9Rcx4TsInbVIo6r6MqGzadfHN2hnZ3iLZlpz/Tt0pEhfhQ== 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=1722508713; x=1722595113; bh=WqQz/r8eUVG5acOxYvOKLNinczBn V7Jqpwj8zkTQ3Ec=; b=AUV/ENi6R1Ojakr0FcGLGm3H1cZp0RnEttd13NdzAQrs +/zWTxa7L+xthB5I79cB+1EBapnnXDfElcRfJNPf8Xdak271M0TJGhKazcNb1jlw 2aHbaK0udUHF4q9ma67TC/gEmBmWwvHKKqOSL7RUy2QKULBESvIkV9+PcrIxvg8b RQBKawVlBzs2DFcvBN9mMaRtMLMKMe0zMVepa9ZgVeEO19QqFsBIbX32grkLRhJn oCOiltzj96gQ3SS3/+CxV10pU4IL8+kAguUbW0gXLkXckJslxty5CyfprM5qXFOp OG0tG+1rOxtcV0MYEqdaWYM1CxXUgMJ22LZbQN4Tgg== 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:32 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 592ffea1 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:37:00 +0000 (UTC) Date: Thu, 1 Aug 2024 12:38:30 +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 05/24] builtin/describe: fix trivial memory leak when describing blob Message-ID: <6deacb8667bfe94cdb5995302490b977b7fd2e8a.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: We never free the `struct strvec args` variable in `describe_blob()`, which thus causes a memory leak. Fix this. Signed-off-by: Patrick Steinhardt --- builtin/describe.c | 1 + t/t9903-bash-prompt.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/builtin/describe.c b/builtin/describe.c index 2957ff7031..954929c514 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -529,6 +529,7 @@ static void describe_blob(struct object_id oid, struct strbuf *dst) traverse_commit_list(&revs, process_commit, process_object, &pcd); reset_revision_walk(); release_revisions(&revs); + strvec_clear(&args); } static void describe(const char *arg, int last_one) diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh index d667dda654..95e9955bca 100755 --- a/t/t9903-bash-prompt.sh +++ b/t/t9903-bash-prompt.sh @@ -8,6 +8,7 @@ test_description='test git-specific bash prompt functions' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./lib-bash.sh . "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh" From patchwork Thu Aug 1 10:38: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: 13750131 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 C4EBE170A3D for ; Thu, 1 Aug 2024 10:38:39 +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=1722508721; cv=none; b=uaKOGqG/J/0Ra01ZW5oMHvWXuKJEcjBYebLoLZrR1lkZfw8rIZMcjHR6PQWoc2oPyhgWtWACs1flxCWdysdtHi1nNTllD6F5Mr0wr/PMhS7bhP/SRXXpdW8dsYnix71yaGL08YiHrmfM0UL8T7Py7M3bdR2OOEokWcBb/lEekNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508721; c=relaxed/simple; bh=kOSDdnpdWr2Eu9Syxp8i9nIcw3LnxJlSxI8UFK8IOyY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WqUyPRizbGgnGVzmzMhEWgRWeASKb45FoV5M/BR5Fq6GIhCvbe3fmbvnlOijC+UpZz5EzCFb4Agmb/FrhQnALUY9sCHV0mqT8sg569xTd22Sad2GUlE/NjfrRep3z/FumC6jtEW9AppZuTcGiGvb1o43VD4ssn1q/K4SEnh5Rxw= 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=AU7eTQM+; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=D1mfOtZa; 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="AU7eTQM+"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="D1mfOtZa" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id EA9E4114ABBF; Thu, 1 Aug 2024 06:38:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 01 Aug 2024 06:38:38 -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=1722508718; x=1722595118; bh=n0w+Ym2LsX KH1LRXKEioscAZijnqB9qeulCPlmrIXHY=; b=AU7eTQM+cj0XMot+QGYYKDq+HX YBR1GOdUbaFWSpxSppGJl2l28OQcOhnTf31NntyftPKC63OPXuuTLz4/wkHpwtEK tvec69+FcEGTgSzaGthWCCf+Fbr95bLvB/Q2dU3ZtIaYIFIX/kDMFNwmWwkhK5Kt Zz2dPGzKiE4g4DB058LvBfALPEUF4ueIzguuKGamDZsjOWusKW3grnt5/iroG0cr S5T+ORcxWdGZd5Z8mqPPWxSHWIY0SOhlaoxB7NxkOySDnL/uGw0VSo8VLD6rONM3 mwP5FSaykthI/FDfMXGjgYJJkcQisCcanbXwHnjBbr3OAUru77b003ZHKHjA== 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=1722508718; x=1722595118; bh=n0w+Ym2LsXKH1LRXKEioscAZijnq B9qeulCPlmrIXHY=; b=D1mfOtZakH5CA7qyxwGpyipvVJ4O0v3js39E/4FAyc1c Z7TarCSiwRjtf0ZFrTw0+MDAanu3TARySL4wy/mEmRlcvzP2NFvjFLURCDXBvwra anqaddcf/qAZ9NQUrgARe9SSWJFP4YS0Ytrb0eoSxaByHOal7TgeyWxNyRKULwiz 4pP+cK4ddIfW2dayCoMZFoxq24UkDMdkJLQ5vt2sqBgb1DsAV9orotsj6KMFdNa4 K59/Y2msF4b2/NjAOjal5JvjEsrzD+o0pdTDF25joNa0+hZ3vgECsvS67nHDciNX sAGPEkHuVuiVj+du4JCQt1pWitlPqHWv1t4EjsG9Wg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:38:37 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 85d79959 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:37:05 +0000 (UTC) Date: Thu, 1 Aug 2024 12:38:35 +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 06/24] builtin/name-rev: fix various trivial memory leaks 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: There are several structures that we don't release after `cmd_name_rev()` is done. Plug those leaks. Signed-off-by: Patrick Steinhardt --- builtin/name-rev.c | 6 ++++-- t/t6007-rev-list-cherry-pick-file.sh | 1 + t/t6120-describe.sh | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 70e9ec4e47..f62c0a36cb 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -677,7 +677,9 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) always, allow_undefined, data.name_only); } - UNLEAK(string_pool); - UNLEAK(revs); + string_list_clear(&data.ref_filters, 0); + string_list_clear(&data.exclude_filters, 0); + mem_pool_discard(&string_pool, 0); + object_array_clear(&revs); return 0; } diff --git a/t/t6007-rev-list-cherry-pick-file.sh b/t/t6007-rev-list-cherry-pick-file.sh index 6f3e543977..2d337d7287 100755 --- a/t/t6007-rev-list-cherry-pick-file.sh +++ b/t/t6007-rev-list-cherry-pick-file.sh @@ -5,6 +5,7 @@ test_description='test git rev-list --cherry-pick -- file' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # A---B---D---F diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 79e0f19deb..05ed2510d9 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -14,6 +14,7 @@ test_description='test describe' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check_describe () { From patchwork Thu Aug 1 10:42:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750171 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 C492D170A17 for ; Thu, 1 Aug 2024 10:43:03 +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=1722508985; cv=none; b=MTKoPI4ePTE7b8AqFjreNYVbDXSWI7kl+Aj+P2aJQwUCTWhlPg/1xiM4UW6ybDJN/M9dW0YuLkPOauL46QpOva6NceimXHPy+eHmVPmZwH1sLoTjmtNoKHJ1cgOJ574fTPB0FLJe7ehEdzhyBp9PuSlj9cKijIKWbsIyb2Rxix8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508985; c=relaxed/simple; bh=+PwiTOy7dbRZrIyY2q2oZWkRUgir+7qP3ftug/YI2/I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kL+dTLmE1xiKIzADTMNGyBNhCy5eo0hqrnssN6PMfInYoHDrDLD26jMDvpR+jDZVAuHPsHoNG0bhsMM+GRFDpi+614nH2eviTQAe+hQrseL3NIrVurdKu/ZjcdAeaQa5tIqqdwx6sgOqSq/orAe2H6CSBwMxhHO7OQFo2ZMXNGg= 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=UdRlRby7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kN/HTev/; 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="UdRlRby7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kN/HTev/" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 1F5C71148363; Thu, 1 Aug 2024 06:43:03 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 01 Aug 2024 06:43:03 -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=1722508983; x=1722595383; bh=OK4FPYT8UC bFpTMME0E4+XysFllslgBwOZlfBdpzp0E=; b=UdRlRby7fAG0f5fae41SCvURrZ Jr/HFtaY0PCdouk2nmuUWJCMj4a5jnoP0xXmRDjnjQxTZA0Dw7ItctQmAtUnav6+ ey5dKd4HG2N+Ix0l23w0PX1cmz/7ZVp6GnV3LEdQykMv4IUcfX0gWfmQsSB9QY9l ix9Ya+H4CP4yEQpQowpiI7TVTxRQGjBGOmcj8kGAEODkVCSubRoQqKms5VoSpcV/ F6alwJpgt4m85HIHYU8VijSVIdMLaVdlbfM+Bi+G1UDv/pwuR/76BvQxC7HjQGFH QccQfdHDdSS0gihT57DDnCmtZrir0NwIDX0A6+yjDEkoSXyX1YoxU1EheQ2g== 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=1722508983; x=1722595383; bh=OK4FPYT8UCbFpTMME0E4+XysFlls lgBwOZlfBdpzp0E=; b=kN/HTev/rxSXKCcxbNMuP/M70LM1SJr7gxn11PExNMfq gtbCBcKn3Af0kpAXra1xrhYIdv+hF3Bm7tPzTTrEe5mD4CQDWhy34oqe8TBd/cyg 9dwvvXWlldGpuD9b7JzWHH+SURg0+ZfFflWHRgoQL6ahlYRLVzwApBv/XVmCUpYQ 2aStTrCUrNqbTClWN4HeyE1jXbFa1EC0I+jFYcXWMIbdMaMRU4O9RMOgT9QO5Jsg npisQF+UnLvTxsXFmQt6DPaVE7OFQx30RmNPvOPX3/asI+2N0Ng8bMwAMzcHuydL VX0HCWIALYqIoDGKgdVOMoCLrDvMilvCjy/Du4rXLA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttdejnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeetueevhffhudefvdegieeuieelgedthfegfedtueevjeejtdfgjeehudejuedtuden ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:43:01 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id a8fe73c0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:41:29 +0000 (UTC) Date: Thu, 1 Aug 2024 12:42:59 +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 07/24] builtin/submodule--helper: fix leaking clone depth parameter 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 submodule helper supports a `--depth` parameter for both its "add" and "clone" subcommands, which in both cases end up being forwarded to git-clone(1). But while the former subcommand uses an `OPT_INTEGER()` to parse the depth, the latter uses `OPT_STRING()`. Consequently, it is possible to pass non-integer input to "--depth" when calling the "clone" subcommand, where the value will then ultimately cause git-clone(1) to bail out. Besides the fact that the parameter verification should happen earlier, the submodule helper infrastructure also internally tracks the depth via a string. This requires us to convert the integer in the "add" subcommand into an allocated string, and this string ultimately leaks. Refactor the code to consistently track the clone depth as an integer. This plugs the memory leak, simplifies the code and allows us to use `OPT_INTEGER()` instead of `OPT_STRING()`, validating the input before we shell out to git--clone(1). Original-patch-by: RubĂ©n Justo Signed-off-by: Patrick Steinhardt --- builtin/submodule--helper.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index f1218a1995..863b01627c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1530,7 +1530,7 @@ struct module_clone_data { const char *path; const char *name; const char *url; - const char *depth; + int depth; struct list_objects_filter_options *filter_options; unsigned int quiet: 1; unsigned int progress: 1; @@ -1729,8 +1729,8 @@ static int clone_submodule(const struct module_clone_data *clone_data, strvec_push(&cp.args, "--quiet"); if (clone_data->progress) strvec_push(&cp.args, "--progress"); - if (clone_data->depth && *(clone_data->depth)) - strvec_pushl(&cp.args, "--depth", clone_data->depth, NULL); + if (clone_data->depth > 0) + strvec_pushf(&cp.args, "--depth=%d", clone_data->depth); if (reference->nr) { struct string_list_item *item; @@ -1851,8 +1851,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) N_("reference repository")), OPT_BOOL(0, "dissociate", &dissociate, N_("use --reference only while cloning")), - OPT_STRING(0, "depth", &clone_data.depth, - N_("string"), + OPT_INTEGER(0, "depth", &clone_data.depth, N_("depth for shallow clones")), OPT__QUIET(&quiet, "suppress output for cloning a submodule"), OPT_BOOL(0, "progress", &progress, @@ -3200,7 +3199,7 @@ static int add_submodule(const struct add_data *add_data) } clone_data.dissociate = add_data->dissociate; if (add_data->depth >= 0) - clone_data.depth = xstrfmt("%d", add_data->depth); + clone_data.depth = add_data->depth; if (clone_submodule(&clone_data, &reference)) goto cleanup; From patchwork Thu Aug 1 10:39:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750132 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 B45023BBE5 for ; Thu, 1 Aug 2024 10:40:02 +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=1722508804; cv=none; b=Af/xF3gejAv6PKD49FVdBh24w04aAOdrNG4S+fgmC/Ou6k0oHrESa8Z70XiW7ceTK+nRTHjlQUhipD5pYF9XNxYvtlGDATIRfYoxx+Prlm1oY8AQvgNpV8URsHTd+45Aq6j+ZQPhhm6CqUzB1tqKwa4cBo+QzUxdcSJToB5VmfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508804; c=relaxed/simple; bh=G72smGaZUHuObuIhNDhO1yl2uIyC6Y9HCIFe8k35nWA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LODguWH4J9sYaDvjtW33MBRCUk4wH8cmkOqXQWzesuuoZRVJeaPsQ12x4cFivxX1IMu1DkaUoPUdfdzf/XLe4+H6I+JQ69frtFtqFm+6cuwY7qiOQtNaZWO2PJtt6ejC6D7BmfzIVh56FdXfXLALy1B4tU9u2g6suyyjcBz5hFs= 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=mu/luFBQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SgV59hrs; 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="mu/luFBQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SgV59hrs" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E7CD4114ABBD; Thu, 1 Aug 2024 06:40:01 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 01 Aug 2024 06:40:01 -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=1722508801; x=1722595201; bh=BRK9SOLZcD tB9zvOF0ZAW7kVjwCVH0Ky2niexwrmjWo=; b=mu/luFBQt8JPuywt9E/gidUv90 KR6sDPu4/7dowipx8o4L1ytEPiB8d7E9/QFq1GLY8N6LMeN2K/A4Wp8DiYJet3hs mhfNsrFwk4msJeR9Dwg7E/NTwb5+27D3ZFax2Oov7KZ0hfSgW/Ea+fp7QkGH8H1u h8uIvr61/JnNuLwI1CghWJ38Tjf9bdgk6n288TsAE49HyUaHA4ltxvE8OZFrN+Md KIssaPN+azkJtaJaah2d52gK2Y1NVUAb9lPM6aNreuoAS2NAHH3kBXbC+YuH65UL 2LkQmZIsiv5GahwSYqvEzTkqgCdcovbUXf5+kAC1B55v6oIvH9nlIVdKZ8vw== 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=1722508801; x=1722595201; bh=BRK9SOLZcDtB9zvOF0ZAW7kVjwCV H0Ky2niexwrmjWo=; b=SgV59hrsoqU8wqPuc3ZLunrZ50/VPFVotvXfvolYEvkm jSRetQG+Kwlv+/tKHyRHNz91kfQ3E3IXmcoNKsVzk1CLKvSM9YcLPofHJtPz3tmY j5fKk0Um8k1+k0P8shjIA/nUwPab38Cqox/3kMEPVuLcbPf7vQD+SxDtzU6y9HGr lCK+mdI8UC/aZC2YqUVeqKl4uaxswktalhBr6IhihQSTQtiNKi5o9dikz2bD10Ua NAWzLxp8DaOm86Fk9bbQEJCNDDu4UW4qEranWmBpeiOwts7eulC8+HK9QwNd7C4D XXlCtSq2soXkx656JZz0pO0ndOYJlIvDtan+a7nsRg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf 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:40:00 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 7ba4d2c7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:38:28 +0000 (UTC) Date: Thu, 1 Aug 2024 12:39:57 +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 08/24] builtin/submodule--helper: fix leaking buffer in `is_tip_reachable` Message-ID: <49c156cebb12e387a49a763595f0846678883b7b.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: The `rev` buffer in `is_tip_reachable()` is being populated with the output of git-rev-list(1) -- if either the command fails or the buffer contains any data, then the input commit is not reachable. The buffer isn't used for anything else, but neither do we free it, causing a memory leak. Fix this. Signed-off-by: Patrick Steinhardt --- builtin/submodule--helper.c | 9 +++++++-- t/t7400-submodule-basic.sh | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 863b01627c..673810d2c0 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2268,6 +2268,7 @@ static int is_tip_reachable(const char *path, const struct object_id *oid) struct child_process cp = CHILD_PROCESS_INIT; struct strbuf rev = STRBUF_INIT; char *hex = oid_to_hex(oid); + int reachable; cp.git_cmd = 1; cp.dir = path; @@ -2277,9 +2278,12 @@ static int is_tip_reachable(const char *path, const struct object_id *oid) prepare_submodule_repo_env(&cp.env); if (capture_command(&cp, &rev, GIT_MAX_HEXSZ + 1) || rev.len) - return 0; + reachable = 0; + else + reachable = 1; - return 1; + strbuf_release(&rev); + return reachable; } static int fetch_in_submodule(const char *module_path, int depth, int quiet, @@ -3222,6 +3226,7 @@ static int add_submodule(const struct add_data *add_data) die(_("unable to checkout submodule '%s'"), add_data->sm_path); } ret = 0; + cleanup: string_list_clear(&reference, 1); return ret; diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 981488885f..098d8833b6 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -12,6 +12,7 @@ subcommands of git submodule. 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 - enable local submodules' ' From patchwork Thu Aug 1 10:40: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: 13750133 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 19BFD3BBE5 for ; Thu, 1 Aug 2024 10:40:06 +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=1722508808; cv=none; b=Fsl/TS9rFuEXJvex3YWLL0/bwTk5zKaXQ4BB8ehrR4uBxr7CmtWyWDiPTcyCUOEW5nP9X9DmQrhfEAsVHEPMqSs4JEBFnLWd+c6fjFpZnAXAP5NHf/GloM+VPKcatzZMdhgZGT1zRsZvHjANTDIB1ciMmluhmz/FA2+mxiE6Crk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508808; c=relaxed/simple; bh=QI26YNJhbOFfDrSze7+Z9uEP8aKbIB9OJ6WFB9SHQWg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gM8AhAV/DfG+gJdEFr+sPNd6ZCKobhmkuUhdxR/XY5b2HYCt74lIix83sNIZl5dliWoQaHMjyHACOek65Us3j7a2YaPP35RRP/k0iFvaqNijF2g0/vYlSV7CydvVg26vI1rDkWWS1HUoCHf9vsI3UqNSl9F7o57nvFxLPX2hyEg= 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=iTu9SFvO; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Qts5DIVO; 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="iTu9SFvO"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Qts5DIVO" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 4F260114ABC4; Thu, 1 Aug 2024 06:40:06 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 01 Aug 2024 06:40:06 -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=1722508806; x=1722595206; bh=s4emRCgYEO /8vstH3IhbBjyi2ymIg9FlBDAHNbKNWxM=; b=iTu9SFvOWqemIA328qWEa3E78D gqgAmbUA2cx/oje8/Mo6uOV0Jo6CboOmcyzhtvGnGkXj3e6urK1zsHM0y3pubs6J ZHbroiOXulWMsO14CmGKMPyS9ACSoc0mOPvG6AZBALuKTvIr7j+Y1/sFm6IodLY8 L5nwdNziB5Oi3ooXUXyqKGLiPNnDxAR7XtnnmzXwLs6nh5GlUYMUAbKfWxldz2UI CWv+gCyp4p324Uwpo6wa/5QqhND3fkBmueDsZf7iXo5zXItRKNkvThb/bq+fH6sH 085qsXkB/FUBHwLs6bvIxNDI67VEhVwOifNwl8KIF4H5uaWh7Xm6dGDvnegQ== 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=1722508806; x=1722595206; bh=s4emRCgYEO/8vstH3IhbBjyi2ymI g9FlBDAHNbKNWxM=; b=Qts5DIVOMUhdYvFVUn4epVR52g+ud3VuaogMhRaQaBDP JLhRLiVy6ytOkrtcW+0rthzcPFxq25aWaV/I7hgvRwIauUBPvw3/3BrGVSxCpgIT W8BKqH7kX3aEyJEgqZ3qpL4KoQpiwPyPcJxXx0sLQPzk5Z/UUoxKN355XTp/7ZN0 DP4R1TG7XDKP0rvVW5pzUWKTQRfwuaW/4zPWoenxY6HObPgSNNMYendgzcspMsZ9 wneQXfEPNKGHRNbcW5lK1B5pUJfa1mD1HGzZi1ikvlnE227Fw0lWOQC7JYM5U4mc g1fP9Kp+heg/lg2cUHkyoytQkY5s18nFuMe7jorNZQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf 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:40:05 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 617d6062 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:38:33 +0000 (UTC) Date: Thu, 1 Aug 2024 12:40:02 +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 09/24] builtin/ls-remote: fix leaking `pattern` strings Message-ID: <4330c80905805d51439006e15c64d672ba376291.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: Users can pass patterns to git-ls-remote(1), which allows them to filter the list of printed references. We assemble those patterns into an array and prefix them with "*/", but never free either the array nor the allocated strings. Refactor the code to use a `struct strvec` instead of manually tracking the strings in an array. Like this, we can easily use `strvec_clear()` to release both the vector and the contained string for us, plugging the leak. Helped-by: Taylor Blau Signed-off-by: Patrick Steinhardt --- builtin/ls-remote.c | 24 ++++++++++-------------- t/t5535-fetch-push-symref.sh | 1 + 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index debf2d4f88..5b61af5d78 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -19,17 +19,16 @@ static const char * const ls_remote_usage[] = { * Is there one among the list of patterns that match the tail part * of the path? */ -static int tail_match(const char **pattern, const char *path) +static int tail_match(const struct strvec *pattern, const char *path) { - const char *p; char *pathbuf; - if (!pattern) + if (!pattern->nr) return 1; /* no restriction */ pathbuf = xstrfmt("/%s", path); - while ((p = *(pattern++)) != NULL) { - if (!wildmatch(p, pathbuf, 0)) { + for (size_t i = 0; i < pattern->nr; i++) { + if (!wildmatch(pattern->v[i], pathbuf, 0)) { free(pathbuf); return 1; } @@ -47,7 +46,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) int status = 0; int show_symref_target = 0; const char *uploadpack = NULL; - const char **pattern = NULL; + struct strvec pattern = STRVEC_INIT; struct transport_ls_refs_options transport_options = TRANSPORT_LS_REFS_OPTIONS_INIT; int i; @@ -93,13 +92,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) packet_trace_identity("ls-remote"); - if (argc > 1) { - int i; - CALLOC_ARRAY(pattern, argc); - for (i = 1; i < argc; i++) { - pattern[i - 1] = xstrfmt("*/%s", argv[i]); - } - } + for (int i = 1; i < argc; i++) + strvec_pushf(&pattern, "*/%s", argv[i]); if (flags & REF_TAGS) strvec_push(&transport_options.ref_prefixes, "refs/tags/"); @@ -136,7 +130,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) struct ref_array_item *item; if (!check_ref_type(ref, flags)) continue; - if (!tail_match(pattern, ref->name)) + if (!tail_match(&pattern, ref->name)) continue; item = ref_array_push(&ref_array, ref->name, &ref->old_oid); item->symref = xstrdup_or_null(ref->symref); @@ -158,5 +152,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) if (transport_disconnect(transport)) status = 1; transport_ls_refs_options_release(&transport_options); + + strvec_clear(&pattern); return status; } diff --git a/t/t5535-fetch-push-symref.sh b/t/t5535-fetch-push-symref.sh index e8f6d233ff..7122af7fdb 100755 --- a/t/t5535-fetch-push-symref.sh +++ b/t/t5535-fetch-push-symref.sh @@ -2,6 +2,7 @@ test_description='avoiding conflicting update through symref aliasing' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' From patchwork Thu Aug 1 10:40: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: 13750134 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 B00C93BBE5 for ; Thu, 1 Aug 2024 10:40:11 +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=1722508813; cv=none; b=BLc6TAJEwyucpbqJ02+rXMc7Agmcy0FCPJ+8M/wD/s1P8TXIHf4877y5ymWEDfMAafUDaW66CqugqsmFcAulga7bMDvW/meHEMALpLktDKLQpbUfD4BeiJJrBRxDbZKbPooEWl2go8Z8NW9ODfhyBtgxO31UpecRQn9MsxaE9Yk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508813; c=relaxed/simple; bh=IKITCKsjskzBqFnZjBot6MSjQLu7F8ZLxJByBnNybf0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eUXnZfS+pnwdaunxyQRWT99gFJl6U6eUibISPbnvaQwZK+03bPkLu7l+x+1K4odixvs3HKhAMA4Li9xgQt3ZXhtxHPkBvoGqdWWAzFKx4i0pk+XrQlQ91r8/S01iFlAnsotpJYeLywoZa96jXPWN57d/5QJr8VF2hdgSUGjwyfA= 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=RWkYJF/A; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FvXzidqb; 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="RWkYJF/A"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FvXzidqb" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfout.nyi.internal (Postfix) with ESMTP id C2D9C1388049; Thu, 1 Aug 2024 06:40:10 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Thu, 01 Aug 2024 06:40:10 -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=1722508810; x=1722595210; bh=JU25/SsTIp SAslIaW7lgh6M5OOzhHTwL1rRX/ojlVmQ=; b=RWkYJF/AsciZE+k52mwVVsPPZD pZqjuO2DRzO38ZuLfUdK5+aKZTLi2+RZPYmPku3waShEvsQKL33BefxwBbVineNc 0iFuTjAUFjT0Fsu0279e720v8FsbXwqeilb6zDX3feRlM8txMERLSvt2goZ30AL5 r0hrmoLXwiVHTRbDvlmQ3ULfRWy7wTvBkOYChrnt6UauMBeKsmDXfNDD3o+t5Wvm 7ycHJoHScs5ilH8xPRITf9t19XQwxIQ3w9fXX61N7nZ2OrZ4GWMDAhCtKPkj/Atl kn3GA+GG1tPct3vO2OlT/vdqcSo1IxQn8j7BMeEGuP6u4XOKVU4cj2bnvewA== 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=1722508810; x=1722595210; bh=JU25/SsTIpSAslIaW7lgh6M5OOzh HTwL1rRX/ojlVmQ=; b=FvXzidqbBUED0zXFZpxnp8AXq5wU3RN74hRmXZfYtc7x P/VvrGA0h/KpuPsx/CaWxrcxWpPQJm1S4ExvSxuBLqpIVcCekqGLTt3nFzhOQyoz CKY5Xvu4cCjY+QRjbF6bqeBKCbBB4K1LZJ18fCE64dIljvSKkr/RwwQezF6ZD+RJ 69GstoD9IwqbbFRgD7kJ5z8BhJsDJ4a5jcqA4/VZrFzD0xAPqGBnd8Z/YYnFD7jS Xccr2asufeODULaSjea6iUlTGVU3WMq2ZPAs+uIDY/niwsuxr4VmyOflEcvWvKc9 tVgm9s8Tt2edmhfMjJRqMEWPMsYBwRAzHY05tJiWiw== 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:40:09 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 874eed28 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:38:38 +0000 (UTC) Date: Thu, 1 Aug 2024 12:40:07 +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 10/24] builtin/remote: fix leaking strings in `branch_list` Message-ID: <2e3f76b428a0304d6e638dc4b8ff575dbd365691.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: The `struct string_list branch_list` is declared as `NODUP`, which makes it not copy strings inserted into it. This causes memory leaks though, as this means it also won't be responsible for _freeing_ inserted strings. Thus, every branch we add to this will leak. Fix this by marking the list as `DUP` instead and free the local copy we have of the variable. Signed-off-by: Patrick Steinhardt --- builtin/remote.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 08292498bd..303da7f73f 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -258,7 +258,7 @@ struct branch_info { char *push_remote_name; }; -static struct string_list branch_list = STRING_LIST_INIT_NODUP; +static struct string_list branch_list = STRING_LIST_INIT_DUP; static const char *abbrev_ref(const char *name, const char *prefix) { @@ -292,8 +292,8 @@ static int config_read_branches(const char *key, const char *value, type = PUSH_REMOTE; else return 0; - name = xmemdupz(key, key_len); + name = xmemdupz(key, key_len); item = string_list_insert(&branch_list, name); if (!item->util) @@ -337,6 +337,7 @@ static int config_read_branches(const char *key, const char *value, BUG("unexpected type=%d", type); } + free(name); return 0; } From patchwork Thu Aug 1 10:40: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: 13750135 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 151E6170A37 for ; Thu, 1 Aug 2024 10:40:16 +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=1722508819; cv=none; b=pXL4c/I1CO1LHYGQBaQMXa/0IE5Hx8F46DCC3WvhEoQz8g9FC1EpN1zT5J+yQ6j7LZCnDtQWHTj7S7ow7lw7hFIyBjUpc2Hk+7/ZCzVV19yiYU9qNqWLCMfqqfHNQoAGUveegA8kdEOIYFT4GsXH4NIGx4BylpiXH9rA9TkW6zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508819; c=relaxed/simple; bh=CmCcMWs7koI06t9cpBHKGhXeVAelThvnsDyma3KmSUM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qEg14ysT5NPmHrgeYRGoTfkL3cSvsA/8wCOPguWY6A/MmBovEQ0eiNrr/YL5D0tYepez6zNuJRSTFg76w49wRG/Js/CraMGV3253nCvnNvdYEX9NwVJFYOS3Sq3EBLyGz5zDp0Eo9IdA6GR9tfqF8bKGLViYJZjtzGKq0/ZQR4Q= 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=K67sOxWo; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RJ26aHC0; 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="K67sOxWo"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RJ26aHC0" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3F9B2114AB16; Thu, 1 Aug 2024 06:40:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 01 Aug 2024 06:40:16 -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=1722508816; x=1722595216; bh=6cE/1JLRpA neb87IItSX11QjDbGD3yGvXuNSWAXtWTM=; b=K67sOxWoIpf4AwpXHFRB+U894F X3eNM35ORTs/Sjj8YcDGjweiVxX5LDrEA/YzB+5dbYz1WQBgwilSfEf2C1Kw4Zsr fFo0XgLzf+umfzmDbnlTUBdfrU3QXdYCFkNtYk3mIxTZno48cH5lGr5DC8AL89Zj EuKvhp68SfLFwDiGfOu1x/sOG9XSo3zntk/tyQ1COfzMFxlCkrAufOedg1Oj1GOw trYPrPERlpmmi/yvNfbqfmWp0WxZsRNsgVb+jiKLdm8n+OueqgQB7l+nXnXfIjrx 6ufSUlUf8C+tbk4KUP+PQWpVjBb8scLG4Wvb8sIzoiow7eMNb21c2WIAgSQQ== 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=1722508816; x=1722595216; bh=6cE/1JLRpAneb87IItSX11QjDbGD 3yGvXuNSWAXtWTM=; b=RJ26aHC0avB4Xe7mM6IZht1sp86d+PJuzRwXi0U03QIq V5wbGw0Jl1t+qoRNnGbuRj1TzR5pvBYKRP61hxROAN7gaA24+d8K2V9igvgw/RVm Nmt9Y8rcmfDear2GqB/LK3COfsN/WWNyuF3RtbbPSyJJIXcWkTcavV1qJ8c3d6rV qMmsKG0pTCSooV3DdCcbQ9GQiHSLniamnz1a0uEcgH/0NCUwq+RQ2ICnGHJNuo11 M0CmziAEd9WC9O44lPIa6ZgGJhQ+2X1YZJJRXkfArYxdKmORj0YNcKeJ/wgTnL/W 5GhUhs+POxRBgYtw0x3vcNJH5sBdJpI6ynaRM3u02Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf 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:40:14 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id afe224b0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:38:43 +0000 (UTC) Date: Thu, 1 Aug 2024 12:40:12 +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 11/24] builtin/remote: fix various trivial memory leaks Message-ID: <384203c34ba1d747866dd782165bf81b6280e896.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: There are multiple trivial memory leaks in git-remote(1). Fix those. Signed-off-by: Patrick Steinhardt --- builtin/remote.c | 39 ++++++++++++++++++++++++++++++++------- t/t5512-ls-remote.sh | 1 + t/t5514-fetch-multiple.sh | 1 + t/t5520-pull.sh | 1 + t/t5528-push-default.sh | 1 + t/t5543-atomic-push.sh | 1 + t/t5570-git-daemon.sh | 1 + 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 303da7f73f..9d54fddf8c 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -555,13 +555,16 @@ static int add_branch_for_removal(const char *refname, refspec.dst = (char *)refname; if (remote_find_tracking(branches->remote, &refspec)) return 0; + free(refspec.src); /* don't delete a branch if another remote also uses it */ for (kr = branches->keep->list; kr; kr = kr->next) { memset(&refspec, 0, sizeof(refspec)); refspec.dst = (char *)refname; - if (!remote_find_tracking(kr->remote, &refspec)) + if (!remote_find_tracking(kr->remote, &refspec)) { + free(refspec.src); return 0; + } } /* don't delete non-remote-tracking refs */ @@ -668,7 +671,11 @@ static int config_read_push_default(const char *key, const char *value, static void handle_push_default(const char* old_name, const char* new_name) { struct push_default_info push_default = { - old_name, CONFIG_SCOPE_UNKNOWN, STRBUF_INIT, -1 }; + .old_name = old_name, + .scope = CONFIG_SCOPE_UNKNOWN, + .origin = STRBUF_INIT, + .linenr = -1, + }; git_config(config_read_push_default, &push_default); if (push_default.scope >= CONFIG_SCOPE_COMMAND) ; /* pass */ @@ -688,6 +695,8 @@ static void handle_push_default(const char* old_name, const char* new_name) push_default.origin.buf, push_default.linenr, old_name); } + + strbuf_release(&push_default.origin); } @@ -785,7 +794,7 @@ static int mv(int argc, const char **argv, const char *prefix) } if (!refspec_updated) - return 0; + goto out; /* * First remove symrefs, then rename the rest, finally create @@ -851,10 +860,15 @@ static int mv(int argc, const char **argv, const char *prefix) display_progress(progress, ++refs_renamed_nr); } stop_progress(&progress); - string_list_clear(&remote_branches, 1); handle_push_default(rename.old_name, rename.new_name); +out: + string_list_clear(&remote_branches, 1); + strbuf_release(&old_remote_context); + strbuf_release(&buf); + strbuf_release(&buf2); + strbuf_release(&buf3); return 0; } @@ -945,12 +959,21 @@ static int rm(int argc, const char **argv, const char *prefix) if (!result) { strbuf_addf(&buf, "remote.%s", remote->name); - if (git_config_rename_section(buf.buf, NULL) < 1) - return error(_("Could not remove config section '%s'"), buf.buf); + if (git_config_rename_section(buf.buf, NULL) < 1) { + result = error(_("Could not remove config section '%s'"), buf.buf); + goto out; + } handle_push_default(remote->name, NULL); } +out: + for (struct known_remote *r = known_remotes.list; r;) { + struct known_remote *next = r->next; + free(r); + r = next; + } + strbuf_release(&buf); return result; } @@ -983,8 +1006,10 @@ static int append_ref_to_tracked_list(const char *refname, memset(&refspec, 0, sizeof(refspec)); refspec.dst = (char *)refname; - if (!remote_find_tracking(states->remote, &refspec)) + if (!remote_find_tracking(states->remote, &refspec)) { string_list_append(&states->tracked, abbrev_branch(refspec.src)); + free(refspec.src); + } return 0; } diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh index 42e77eb5a9..d687d824d1 100755 --- a/t/t5512-ls-remote.sh +++ b/t/t5512-ls-remote.sh @@ -5,6 +5,7 @@ test_description='git ls-remote' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh generate_references () { diff --git a/t/t5514-fetch-multiple.sh b/t/t5514-fetch-multiple.sh index 25772c85c5..579872c258 100755 --- a/t/t5514-fetch-multiple.sh +++ b/t/t5514-fetch-multiple.sh @@ -5,6 +5,7 @@ test_description='fetch --all works correctly' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh setup_repository () { diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 47534f1062..1098cbd0a1 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -5,6 +5,7 @@ test_description='pulling into void' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh modify () { diff --git a/t/t5528-push-default.sh b/t/t5528-push-default.sh index 14f7eced9a..bc2bada34c 100755 --- a/t/t5528-push-default.sh +++ b/t/t5528-push-default.sh @@ -4,6 +4,7 @@ test_description='check various push.default settings' 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 bare remotes' ' diff --git a/t/t5543-atomic-push.sh b/t/t5543-atomic-push.sh index 04b47ad84a..479d103469 100755 --- a/t/t5543-atomic-push.sh +++ b/t/t5543-atomic-push.sh @@ -5,6 +5,7 @@ test_description='pushing to a repository using the atomic push option' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh mk_repo_pair () { diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh index f9a9bf9503..c5f08b6799 100755 --- a/t/t5570-git-daemon.sh +++ b/t/t5570-git-daemon.sh @@ -4,6 +4,7 @@ test_description='test fetching over git protocol' 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-git-daemon.sh From patchwork Thu Aug 1 10:40:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750136 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 84453183CDC for ; Thu, 1 Aug 2024 10:40:21 +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=1722508823; cv=none; b=XF5IZGtF5728fXzKBzlOqntLOPNN0bt3IHT4ONQWhu4Hl9vEupfAHQqKXo/f+LLPAo8CXBgCmU/UD00PxVahVB1wa8WBGG08i4301+SEcDA2+Zr1FQ/P0Ei9ijqOmI3EbijPvgOUSV6BOL1o1Nev58Hnp+xKiBNRPdry0urjGoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508823; c=relaxed/simple; bh=M34b48uDZ7XPsZEuq1vnBRsDePuXDZZz4vF8PuXzEg0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cMh9V/cOTVkC0adZLwN/5Na2SoBaxqXTk49xqymippLOir6KfGCI7f7iSonr5CTuWWx+OAdFpU9wzhvYFDOkPPw8YPbmZVXOhzSUQ4zHDeb18lGymwzMUMy7R3+OWkWTm78yEe2r/Te8unk70f6DRPBETOltbsESv0B2l8ZFlWY= 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=mIRbLCzj; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ci+/ll06; 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="mIRbLCzj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ci+/ll06" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A7AC8114821F; Thu, 1 Aug 2024 06:40:20 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Thu, 01 Aug 2024 06:40: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=1722508820; x=1722595220; bh=rYxIf2yhOv HPzGVS/W9w61FPdBbXoPgokTfc3Jpussk=; b=mIRbLCzjtARxrZCZf7h1gNimHE cTRbR2C5zBaZOYwApKl0JjdbwfMuKFHdwqJahJVyTE72iYtjlXYJ8m+cibNiwT8y cQGWvxv2QfUjdUcjQXXAP+Ozw6IoG9hIe5hTWBq/K3TClDEQD1Kx6omlEhx3Ilyj M3fWzi/iuh0ET4XpXWJV5Lqm403INxCEh0TbesA/9o+HXmEdpR89QnoeWwOvuQ3e 87PIcb8brPbR3GhBuRJp5VWByO2r/QSwEuPt7fuC275hb2CkKM6PkzKIWTZNFvSM AnKCxM5mT6i6/s9PjOnh4Ikfzn6hZ892WI1uNDvlEvnw1XkkBxVsoJOlp/fg== 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=1722508820; x=1722595220; bh=rYxIf2yhOvHPzGVS/W9w61FPdBbX oPgokTfc3Jpussk=; b=ci+/ll06D7YOk1SHAm2zvNpz47+BozrpaETUI8Jed4fz BvmzhgV4CL+AtFRmc2KQjBSdciMAwSr+EUtfmsqeQjErxvnyvGp42rKJx2BN0nbj v/6qlc2DI+GFLQmwRoQVkvYWJJNSfTQRB1f0hqzAWtbp8CCY+bpW7tVDtwl0ephf tYEBKtUkw7R3b27yI7VO2MggFSfzo64s3F+wBGCqLyZ3+SBv6SsTIKajtM+98s4s 8B+oQrIJSgZZEsoJml+dl99LgUHqL1FnP7jh+LCEcgPNGTmuhhsaGRd/XbtH7BeF k1ZSj+jR0HTTnDjLPn3VzEUIcsyWlzQXxMW0tgRiDA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:40:19 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id f264a754 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:38:47 +0000 (UTC) Date: Thu, 1 Aug 2024 12:40:17 +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 12/24] builtin/stash: fix various trivial memory leaks 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: There are multiple trivial memory leaks in git-stash(1). Fix those. Signed-off-by: Patrick Steinhardt --- builtin/stash.c | 18 ++++++++++++++++-- t/t2501-cwd-empty.sh | 1 + t/t3903-stash.sh | 1 + t/t3904-stash-patch.sh | 2 ++ t/t3905-stash-include-untracked.sh | 1 + t/t7064-wtstatus-pv2.sh | 1 + 6 files changed, 22 insertions(+), 2 deletions(-) diff --git a/builtin/stash.c b/builtin/stash.c index 46b981c4dd..7f2f989b69 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1521,6 +1521,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q struct strbuf patch = STRBUF_INIT; struct strbuf stash_msg_buf = STRBUF_INIT; struct strbuf untracked_files = STRBUF_INIT; + struct strbuf out = STRBUF_INIT; if (patch_mode && keep_index == -1) keep_index = 1; @@ -1626,7 +1627,6 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q struct child_process cp_add = CHILD_PROCESS_INIT; struct child_process cp_diff = CHILD_PROCESS_INIT; struct child_process cp_apply = CHILD_PROCESS_INIT; - struct strbuf out = STRBUF_INIT; cp_add.git_cmd = 1; strvec_push(&cp_add.args, "add"); @@ -1718,6 +1718,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q done: strbuf_release(&patch); + strbuf_release(&out); free_stash_info(&info); strbuf_release(&stash_msg_buf); strbuf_release(&untracked_files); @@ -1869,6 +1870,8 @@ int cmd_stash(int argc, const char **argv, const char *prefix) OPT_SUBCOMMAND_F("save", &fn, save_stash, PARSE_OPT_NOCOMPLETE), OPT_END() }; + const char **args_copy; + int ret; git_config(git_stash_config, NULL); @@ -1892,5 +1895,16 @@ int cmd_stash(int argc, const char **argv, const char *prefix) /* Assume 'stash push' */ strvec_push(&args, "push"); strvec_pushv(&args, argv); - return !!push_stash(args.nr, args.v, prefix, 1); + + /* + * `push_stash()` ends up modifying the array, which causes memory + * leaks if we didn't copy the array here. + */ + DUP_ARRAY(args_copy, args.v, args.nr); + + ret = !!push_stash(args.nr, args_copy, prefix, 1); + + strvec_clear(&args); + free(args_copy); + return ret; } diff --git a/t/t2501-cwd-empty.sh b/t/t2501-cwd-empty.sh index f6d8d7d03d..8af4e8cfe3 100755 --- a/t/t2501-cwd-empty.sh +++ b/t/t2501-cwd-empty.sh @@ -2,6 +2,7 @@ test_description='Test handling of the current working directory becoming empty' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index a7f71f8126..e4c0937f61 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -8,6 +8,7 @@ test_description='Test git stash' 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-unique-files.sh diff --git a/t/t3904-stash-patch.sh b/t/t3904-stash-patch.sh index 368fc2a6cc..aa5019fd6c 100755 --- a/t/t3904-stash-patch.sh +++ b/t/t3904-stash-patch.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='stash -p' + +TEST_PASSES_SANITIZE_LEAK=true . ./lib-patch-mode.sh test_expect_success 'setup' ' diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh index 1289ae3e07..a1733f45c3 100755 --- a/t/t3905-stash-include-untracked.sh +++ b/t/t3905-stash-include-untracked.sh @@ -5,6 +5,7 @@ test_description='Test git stash --include-untracked' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'stash save --include-untracked some dirty working directory' ' diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh index 11884d2fc3..06c1301222 100755 --- a/t/t7064-wtstatus-pv2.sh +++ b/t/t7064-wtstatus-pv2.sh @@ -4,6 +4,7 @@ test_description='git status --porcelain=v2 This test exercises porcelain V2 output for git status.' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh From patchwork Thu Aug 1 10:40:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750137 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 1EA8A170A37 for ; Thu, 1 Aug 2024 10:40:25 +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=1722508827; cv=none; b=f6CTp8K3LzJvhtDf9UzbbYAyWR3/lyRD6cLx3CUqMybsQIn5MxQ1BAQAkyjHDISCunWwJkh7UTkKEjExkjwgnnDSpj7b96Gyy5C1hZ5TnjFG17KJvRT6mJN6duRD0cr9PTrTpEQVwPlf2/bmFPMm7DXFI2e5E1dQLcqzJEoq2BM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508827; c=relaxed/simple; bh=MsyvqIJImmYrk/N/gbvJ+kfwNtmF/pDzCtTaMyuhKIY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Rs+fSmQhtJ6RZobtdPAproXxDz9sxmKCVSuNJXDF6uMnGa60hfv/NpV0pz7O4lRPJabzTbd9MRgzAbr+ALFwfKkwVT8n9ccz+olFlUczGgfnWtBDX2IKEIzPcLr2K+OZR02mkrJbx7Fd0W/u3Q2J9TsJDzG6a36JFwwSyOcuDWY= 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=PK8OSMx2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NyU5wdOH; 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="PK8OSMx2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NyU5wdOH" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 23CBE1388015; Thu, 1 Aug 2024 06:40:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 01 Aug 2024 06:40:25 -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=1722508825; x=1722595225; bh=Lz6+bQErON SkVnPLEu/e0DC6ehcFzq3A+MhfAMl1RQs=; b=PK8OSMx2ATHL8Jfgt5NubUFDt3 dJtL7QYz8oVTD8Qusy5qf8PrjjCTROY6achtNtPQD45uXFTe2CTmlpOknYCmfHkB fdRoRxbRIOJpUhRW/tLN/WM80Yp6veQiaC7JdguBavxZFk/FqTKYg+U7SFBjUHiW rB2w3XvukMqQynem+W6dubs8WWP3/kRP7rLK9ye9m4bsvM4pgyC0lL52Xqzh1SFB mexgDgakU9I1LM3tP+P8wGG0WqZ3no1Haq33ZWHhs8YEt3OCyQsoiqPGJcl23FSo QqGnIOK4LhUPOFSNT8SLZMZu0rV23odRiroK9zcwHKC7jCEpcY0jErYvktEQ== 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=1722508825; x=1722595225; bh=Lz6+bQErONSkVnPLEu/e0DC6ehcF zq3A+MhfAMl1RQs=; b=NyU5wdOH8czmHvH45IMxmo977kD+lw2IVBypHoGu+FnL nn4BUL1vMs2ZZ781+r9a8qSy7EvUOzrrx8ZyA76KozCZQBnoh2cizLetbFpG7Xw+ VRwMKnw6A2BduBeLX/0BNipvR2hcmgltR2pJREQyJSRuKuLoGbsXg58kgvRH8PqV /d2sJNWZkr5Jye19szoHcI9vf+vbrWboMF5OWKt/8rY46A7aElPWANcx6aTcix9n 44bpdhseuNNJsAsOZJM/pu4EHWmwAVAil/teRbB7skLe39p38g5wOKWn0UmpHhB0 up4FNUNDzGKfIGmED7T6oOzj5Yx7jOux3oSkZIcHcQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf 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:40:23 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 712c7e06 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:38:52 +0000 (UTC) Date: Thu, 1 Aug 2024 12:40:21 +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 13/24] builtin/rev-parse: fix memory leak with `--parseopt` Message-ID: <034c416d4693701cecc3201b9f8d9839fd99c1ab.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: The `--parseopt` mode allows shell scripts to have the same option parsing mode as we have in C builtins. It soaks up a set of option descriptions via stdin and massages them into proper `struct option`s that we can then use to parse a set of arguments. We only partially free those options when done though, creating a memory leak. Interestingly, we only end up free'ing the first option's help, which is of course wrong. Fix this by freeing all option's help fields as well as their `argh` fields to plug this memory leak. Signed-off-by: Patrick Steinhardt --- builtin/rev-parse.c | 5 ++++- t/t1502-rev-parse-parseopt.sh | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 2e64f5bda7..5845d3f59b 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -553,7 +553,10 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix) strbuf_release(&sb); strvec_clear(&longnames); strvec_clear(&usage); - free((char *) opts->help); + for (size_t i = 0; i < opts_nr; i++) { + free((char *) opts[i].help); + free((char *) opts[i].argh); + } free(opts); return 0; } diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh index b754b9fd74..5eaa6428c4 100755 --- a/t/t1502-rev-parse-parseopt.sh +++ b/t/t1502-rev-parse-parseopt.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test git rev-parse --parseopt' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check_invalid_long_option () { From patchwork Thu Aug 1 10:40: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: 13750138 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 33DDE184557 for ; Thu, 1 Aug 2024 10:40: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=1722508832; cv=none; b=LNNBNQ0V/9TulrDsYt+j5nTN2y1CmFcELoE1YOBgGs9f4h8k834/4iMdSIwUDUkUBsCOiNnHfcNmFkxlGczhrng8uPwYGSbbWfctwTSoC9MxUuPflrk2jA9FVAwuwAmc+lP6d/TM2Wx7k3c1+9qeHbVStj0ocuzHXjxUOh/qnQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508832; c=relaxed/simple; bh=aD4gKYdSCRdZqHM4ldZE8WWVQqVM4nExvEMDOUej5ls=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=D7fymeIpVRNEZY2Vwv7BIKyNDPDSkzf9kQL9Anr4XAC0lsKxOUYAszIz8mTymBwVa16GOQjAr9UfDy+2uL9pX4aUAEYyIyowj+z8AMajQSe/R0spcM3uT6C4UJCn+q7Ra7HfGv7h/a42xDqP4Vjie4UCYEhO5i8yl9ekMthVpmQ= 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=XsJMrVra; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=pqRBbSxP; 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="XsJMrVra"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="pqRBbSxP" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 8A7851388071; Thu, 1 Aug 2024 06:40:30 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Thu, 01 Aug 2024 06:40:30 -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=1722508830; x=1722595230; bh=eM2BI1+g22 fBnNfLtyVDuJyfrz8KW8hHjJ72M3hISAY=; b=XsJMrVraPpXeT2z/Av4VBlx9R8 Fp1oXeI7VmLWxtbNsnEeP9BfweIadEuajUpqaq14m772dVcTlcY5rPrVfgjFcQJe ymopG4Z4yu7d4ZM/j0+F3l7uTK75pZGJdAxgK5Zx6iXvGHQKY+BwcLlgVyToE+JD HxZWOYSCZcutCWVlQjb0Lkfg5TLf66415YFoh3BxxOxFmFvRRAiheIZEYsNa+ksQ gkdOHL9XAw7tfTT1sHkkEG3yRS3w/CcPOLXYgsyw+XdVY/tW/4iAjRFMFVD4gijq b9oCkW3ZGs8uGzgQyGdIz5EWgNjnytxvNk6V6am5yUTwyFriRJNoZHnZ4mDQ== 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=1722508830; x=1722595230; bh=eM2BI1+g22fBnNfLtyVDuJyfrz8K W8hHjJ72M3hISAY=; b=pqRBbSxPgUNUTGQBXS+zI0TmGgvP/tIQJ/ErB1Z/ZUvR Aacs6KnUktQSNLJX7GnjnzrhtRxtrNABYVlkUUWyHPHG88tALNrHo8hRw5f8UJhr 39Hk8PIpN95By23OfwfbOsvGpw0Z8OxU/F9nqd3y1lG16K7PZa5MjFSh283Iz9tR 03pgvjvVWC57Fyed+jma0vakEzG4aShkSTy0HgFXtuVXWMQ9vHvfqXlmwKkp2Qm9 U8ynhu76b7DkLZkbs5pHy6ZJ7Qhon188KJbzQnsO5gTk40uZwlF2juyseSBiwTkw 0Tugwm+ovGOqB3NVSPZLPLLt4/t0muOPxMtyiuARzQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf 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:40:29 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 36972b5f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:38:57 +0000 (UTC) Date: Thu, 1 Aug 2024 12:40:26 +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 14/24] builtin/show-branch: fix several memory leaks Message-ID: <20a40e2fd49468f3c406a3124c06cd2b4a9f58eb.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: There are several memory leaks in git-show-branch(1). Fix them. Signed-off-by: Patrick Steinhardt --- builtin/show-branch.c | 52 +++++++++++++++++++++++++++++------------- t/t3202-show-branch.sh | 1 + t/t6010-merge-base.sh | 1 + 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/builtin/show-branch.c b/builtin/show-branch.c index d72f4cb98d..7d797a880c 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -502,14 +502,14 @@ static int rev_is_head(const char *head, const char *name) return !strcmp(head, name); } -static int show_merge_base(struct commit_list *seen, int num_rev) +static int show_merge_base(const struct commit_list *seen, int num_rev) { int all_mask = ((1u << (REV_SHIFT + num_rev)) - 1); int all_revs = all_mask & ~((1u << REV_SHIFT) - 1); int exit_status = 1; - while (seen) { - struct commit *commit = pop_commit(&seen); + for (const struct commit_list *s = seen; s; s = s->next) { + struct commit *commit = s->item; int flags = commit->object.flags & all_mask; if (!(flags & UNINTERESTING) && ((flags & all_revs) == all_revs)) { @@ -635,7 +635,7 @@ static int parse_reflog_param(const struct option *opt, const char *arg, int cmd_show_branch(int ac, const char **av, const char *prefix) { struct commit *rev[MAX_REVS], *commit; - char *reflog_msg[MAX_REVS]; + char *reflog_msg[MAX_REVS] = {0}; struct commit_list *list = NULL, *seen = NULL; unsigned int rev_mask[MAX_REVS]; int num_rev, i, extra = 0; @@ -692,6 +692,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) parse_reflog_param), OPT_END() }; + const char **args_copy = NULL; + int ret; init_commit_name_slab(&name_slab); @@ -699,8 +701,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) /* If nothing is specified, try the default first */ if (ac == 1 && default_args.nr) { + DUP_ARRAY(args_copy, default_args.v, default_args.nr); ac = default_args.nr; - av = default_args.v; + av = args_copy; } ac = parse_options(ac, av, prefix, builtin_show_branch_options, @@ -780,7 +783,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) } for (i = 0; i < reflog; i++) { - char *logmsg; + char *logmsg = NULL; char *nth_desc; const char *msg; char *end; @@ -790,6 +793,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) if (read_ref_at(get_main_ref_store(the_repository), ref, flags, 0, base + i, &oid, &logmsg, ×tamp, &tz, NULL)) { + free(logmsg); reflog = i; break; } @@ -842,7 +846,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) if (!ref_name_cnt) { fprintf(stderr, "No revs to be shown.\n"); - exit(0); + ret = 0; + goto out; } for (num_rev = 0; ref_name[num_rev]; num_rev++) { @@ -879,11 +884,15 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) commit_list_sort_by_date(&seen); - if (merge_base) - return show_merge_base(seen, num_rev); + if (merge_base) { + ret = show_merge_base(seen, num_rev); + goto out; + } - if (independent) - return show_independent(rev, num_rev, rev_mask); + if (independent) { + ret = show_independent(rev, num_rev, rev_mask); + goto out; + } /* Show list; --more=-1 means list-only */ if (1 < num_rev || extra < 0) { @@ -919,8 +928,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) putchar('\n'); } } - if (extra < 0) - exit(0); + if (extra < 0) { + ret = 0; + goto out; + } /* Sort topologically */ sort_in_topological_order(&seen, sort_order); @@ -932,8 +943,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) all_mask = ((1u << (REV_SHIFT + num_rev)) - 1); all_revs = all_mask & ~((1u << REV_SHIFT) - 1); - while (seen) { - struct commit *commit = pop_commit(&seen); + for (struct commit_list *l = seen; l; l = l->next) { + struct commit *commit = l->item; int this_flag = commit->object.flags; int is_merge_point = ((this_flag & all_revs) == all_revs); @@ -973,6 +984,15 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) if (shown_merge_point && --extra < 0) break; } + + ret = 0; + +out: + for (size_t i = 0; i < ARRAY_SIZE(reflog_msg); i++) + free(reflog_msg[i]); + free_commit_list(seen); + free_commit_list(list); + free(args_copy); free(head); - return 0; + return ret; } diff --git a/t/t3202-show-branch.sh b/t/t3202-show-branch.sh index a1139f79e2..3b6dad0c46 100755 --- a/t/t3202-show-branch.sh +++ b/t/t3202-show-branch.sh @@ -2,6 +2,7 @@ test_description='test show-branch' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'error descriptions on empty repository' ' diff --git a/t/t6010-merge-base.sh b/t/t6010-merge-base.sh index 44c726ea39..f96ea82e78 100755 --- a/t/t6010-merge-base.sh +++ b/t/t6010-merge-base.sh @@ -6,6 +6,7 @@ test_description='Merge base and parent list computation. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh M=1130000000 From patchwork Thu Aug 1 10:40: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: 13750139 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 E5382188019 for ; Thu, 1 Aug 2024 10:40:35 +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=1722508837; cv=none; b=V3qjFbt/3Uiv44IG/OpP2CWtir0r3E5npZOGqJOlAUUJcFULSAp411gkkos5BOil5eVjuqTcwmGBa5FSR8TEKsN1Lj0MD0KlMD52H83Hz5HeU4nq3JPsC1ZWQDLspoXZwoB6CUlryN3WZYe01mM/sSqU7CjZ68GZL/LMiGQxyqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508837; c=relaxed/simple; bh=i9NdLqEp7I8/y+itB1YKYeKHBjVnm5CyGcj6rj9sZiI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=t+767RcymrU+7MBgyEPKLQxwv7RHt/l3lhYA5H8KlAlZsDEAANfb8FZU9jk++jfp9+/fjtARu0NmDgTdvGQRc5YBNnaOEt5j6X8755l2vaQ157G88MrG4DUs8l1HDjtuvCceJw1EQEzq6O4dLDN+xJAaRxlvwdbA6FXm0CUSPdM= 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=Zw96EA4d; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qcEzT7iH; 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="Zw96EA4d"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qcEzT7iH" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id EF3CC114ABC8; Thu, 1 Aug 2024 06:40:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 01 Aug 2024 06:40:34 -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=1722508834; x=1722595234; bh=NYOjR45wct yVMdDeaXLvx4vi8xbiziHV21etTV7SUTw=; b=Zw96EA4dAZvxmHmjdp07O2+cIz 5LFaVKB/WiI+Cpr7XiHxL1Ct8SCLaoOy21cLxmQ2Czfz/u70NxdIT0o7WOTafoE9 pjHH+zYy1Tsk461Gulnyh+LG8DRYkqZJM6TPrjEnlAsMH7ujroTDlA7Ggg0+umht VbDquL+S2G+JlQY9TeDZ+2jm2Mf90SZ2fuMZHfvgc7ApohXkIKWLLDMBfgHtl1gJ NjN4yKmIfajf9oj34DGn8Dchdam+m9HcSxnGewPwkhBumGdWddwvVUUURFvA1B2G IwKmWVSXR7DIe9z5QhzKu732IssKd7odn6zRHmifDIRsQukXVIbIsJC+wwhg== 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=1722508834; x=1722595234; bh=NYOjR45wctyVMdDeaXLvx4vi8xbi ziHV21etTV7SUTw=; b=qcEzT7iHZnC7YTHE+K/znUqv2puJIKEPu/7QaFvwKOsn EU6BS+tzHaX5N06einbK5zzTA97mdFx+XX7dmJPhC3syzxjg2A7PgjU9xS3cYoyD vEOU7mq6rQdIkzSrUauT4mnQrEwerlpxa3G16j29AkYKmwOQ2K8X/zNleBVjKdwb U5/69rYyKb0bGfsm1nS+QRsEwKENzn9ZtGfMahsNJYX08pax2vy8uUBSCtugjxdX Rs1RiZbLSfZEOoQDH0uOkYYjUCUxjRkZNFEqHt3QF72KjYSPP+zdpa05DR7hMZjy OxDy7uaQhxEsgRIvKwnO3+J1qgGiWL8vqzAW3MW0Hg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:40:33 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id fccb4e9d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:39:02 +0000 (UTC) Date: Thu, 1 Aug 2024 12:40:31 +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 15/24] builtin/credential-store: fix leaking credential 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 never free credentials read by the credential store, leading to a memory leak. Plug it. Signed-off-by: Patrick Steinhardt --- builtin/credential-store.c | 1 + t/t0302-credential-store.sh | 2 ++ t/t0303-credential-external.sh | 1 + 3 files changed, 4 insertions(+) diff --git a/builtin/credential-store.c b/builtin/credential-store.c index 494c809332..97968bfa1c 100644 --- a/builtin/credential-store.c +++ b/builtin/credential-store.c @@ -218,5 +218,6 @@ int cmd_credential_store(int argc, const char **argv, const char *prefix) ; /* Ignore unknown operation. */ string_list_clear(&fns, 0); + credential_clear(&c); return 0; } diff --git a/t/t0302-credential-store.sh b/t/t0302-credential-store.sh index 716bf1af9f..f83db659e2 100755 --- a/t/t0302-credential-store.sh +++ b/t/t0302-credential-store.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='credential-store tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-credential.sh diff --git a/t/t0303-credential-external.sh b/t/t0303-credential-external.sh index 72ae405c3e..8aadbe86c4 100755 --- a/t/t0303-credential-external.sh +++ b/t/t0303-credential-external.sh @@ -29,6 +29,7 @@ you can set GIT_TEST_CREDENTIAL_HELPER_SETUP to a sequence of shell commands. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-credential.sh From patchwork Thu Aug 1 10:40:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750140 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 04137170A37 for ; Thu, 1 Aug 2024 10:40:41 +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=1722508842; cv=none; b=SrB/469dHUDkjM9Y712f1quBXFNGmkdUcJ7NjaSMuJf+g1w6+yGn2S5A/2YfouMjhtN457cq7SilRGAd7pSgUwQIQGd6NI7l5QN5oZfSTKRqttGUgktz8wBkbe8vwwDYo7pQ3iz2gQcrbm1M4LeFMcLE5BYGqNGK9JOB0fQ9XMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508842; c=relaxed/simple; bh=OAUbzsIIPTgEINdOEqY0T+t5n5yfOxlR7yGAvlCYSrI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZDIYQMnmGc8pKoZGsy+kv2b6xODb7P5kH4SF4htxW0wGUDZt1pVMMPX/5qpS3pZtOWvGyQh3vo4mMgdFUDEKZdgpLkgDbBTCHsQ102uB2yEWfiB9oSs/KBz3OrgLJzUjzTgh6f/iYUKMKbLtjCC16ZHJMSGhek/UfeCznkeLB4A= 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=ivr15qCo; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=psmHp61E; 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="ivr15qCo"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="psmHp61E" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 52B07114ABD4; Thu, 1 Aug 2024 06:40:40 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 01 Aug 2024 06:40:40 -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=1722508840; x=1722595240; bh=osvFIp2dSs R/ea8x13yG9yC6tP/BivzLoCuEqWV7udg=; b=ivr15qColbhJFfhTXGols8yB8k I2YnVZA1YJAKkQVFn37NMdOO4vueS1h530ouAZi7AJbP/O6se8P7nlaDwYkv4fHv bkiTRCi9YO+NGm4PfGlkXqhlccfLzgpYb0V33obXI8vBLT31/NKY1XWgWz3BAJGY MTjps1KHpXurm5yFmHnYRItqnUFVSGBA+wgUPZs3D8AeAEcrhwjZPU6QU4gbw5UU t8/oosjwIcf0IqBHIwoMbJolXaFhHz9nrmmYQYNr5yybbP3Wui1JMhwl7IedOIde E2TUITV73dWBNYrEok7dM04dgJQRbrM/X0czaOxAeceNLgGbyR4vNL4WCqUQ== 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=1722508840; x=1722595240; bh=osvFIp2dSsR/ea8x13yG9yC6tP/B ivzLoCuEqWV7udg=; b=psmHp61EmMBx0tCgBmjwFj9x4qAwcFxIeQ7wMyba32FF 52pGr0WfQH9w80VITddY1KAzeIidk9/QC7OfJNl5MxFT+t9PdfMMQ4BxECCEQtCU SWivKK9PlLmY4D50am8Bgd9vlgP2aIcTJL8kzELrO5WUuKnhALNHLiMpjNZ+C5Su QkMSsQ4tW9K0Lu2Txz3wHinaQgZyYzNHlNBKG++VbU0rc72AvdknbgQCSCd7LgPc tD9Tt11PtsWq6W8vS1qWZOPI5MzFBio/VBzpDcbFvkfSYxYjyHWSNdZctTlKL2ZP 46pbvEK/AqWhUBSy+ew2ckRuXtQOQuuOUnT1b/a6Nw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:40:39 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id be1d8fda (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:39:07 +0000 (UTC) Date: Thu, 1 Aug 2024 12:40:36 +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 16/24] builtin/rerere: fix various trivial memory leaks Message-ID: <76d81c8ae1e99d3160a2535c2fd93fde0734e86b.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: There are multiple trivial memory leaks in git-rerere(1). Fix those. Signed-off-by: Patrick Steinhardt --- builtin/rerere.c | 8 +++++++- rerere.c | 9 +++++++-- t/t2030-unresolve-info.sh | 1 + t/t4200-rerere.sh | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/builtin/rerere.c b/builtin/rerere.c index b2efc6f640..81b65ffa39 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -73,11 +73,17 @@ int cmd_rerere(int argc, const char **argv, const char *prefix) if (!strcmp(argv[0], "forget")) { struct pathspec pathspec; + int ret; + if (argc < 2) warning(_("'git rerere forget' without paths is deprecated")); parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv + 1); - return rerere_forget(the_repository, &pathspec); + + ret = rerere_forget(the_repository, &pathspec); + + clear_pathspec(&pathspec); + return ret; } if (!strcmp(argv[0], "clear")) { diff --git a/rerere.c b/rerere.c index 3a3888cce2..525ed6cc1e 100644 --- a/rerere.c +++ b/rerere.c @@ -1107,7 +1107,7 @@ static int rerere_forget_one_path(struct index_state *istate, int rerere_forget(struct repository *r, struct pathspec *pathspec) { - int i, fd; + int i, fd, ret; struct string_list conflict = STRING_LIST_INIT_DUP; struct string_list merge_rr = STRING_LIST_INIT_DUP; @@ -1132,7 +1132,12 @@ int rerere_forget(struct repository *r, struct pathspec *pathspec) continue; rerere_forget_one_path(r->index, it->string, &merge_rr); } - return write_rr(&merge_rr, fd); + + ret = write_rr(&merge_rr, fd); + + string_list_clear(&conflict, 0); + string_list_clear(&merge_rr, 1); + return ret; } /* diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh index be3fcdde07..b3f6bc97b5 100755 --- a/t/t2030-unresolve-info.sh +++ b/t/t2030-unresolve-info.sh @@ -5,6 +5,7 @@ test_description='undoing resolution' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check_resolve_undo () { diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh index b0a3e84984..213b36fb96 100755 --- a/t/t4200-rerere.sh +++ b/t/t4200-rerere.sh @@ -25,6 +25,7 @@ test_description='git rerere 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' ' From patchwork Thu Aug 1 10:40: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: 13750141 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 6B038189910 for ; Thu, 1 Aug 2024 10:40:46 +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=1722508847; cv=none; b=Dwq9YE3GFE594e5NJFgjYiigvNCEsTiLYg0ayADytgvohsrVF4A40nI5yqjVPhwZQ9kcyfftUwc/d3vWmaYclCSs0RUyJzaDkajfvGttLzXshhB/oc5qZAZegU/+dVP0Gcx6pfWFZvujmlim4vwTmXc1pI7wXhgk+gUavoAdW1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508847; c=relaxed/simple; bh=2bJTOHbTuYlnf6z+SCiVCdJ+6es/vvwIkH5X2+K/YM0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tiKZbmviS9TW4VOSA35PwLPGLcsQLX6soUraAgcSND31IO2r5XuSAom766t650GKxHX9t10csAwIYTl2JbyeW+/FbcHCkFaajv065viiJRzpUawZL5ULCR3U35LOnAgi1Px9wBLGBBjjDQja6Q9WrBgLitakpfaD/ZGbSkf7Ifs= 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=l2wAnavG; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mnNtSrXH; 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="l2wAnavG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mnNtSrXH" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id BD452114ABD2; Thu, 1 Aug 2024 06:40:45 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Thu, 01 Aug 2024 06:40:45 -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=1722508845; x=1722595245; bh=xF9m/dypcJ JxDD63UOCwEm1cn6P7L62v+ssoUYQOKvU=; b=l2wAnavGhHolEvLRl7NIgAY5wT huvlCyhqunvlJqscyTRJnSgsktTtGY4ataTDHnoE3hfhQ20/3N4TFxFVxQuf/IDK d8qlXnqO8Gi5msB5cR4W9Y98kMXspWkcZADpZGu/SkMDpZ/vJepMfPXMc91BZZd2 TEQjzgTTnJLgLAa1iqkUUwBXtFk9fWQto7QriYJ2J3IDYHxHu5p+E3cTJ1kBNNFi K2sEbpx36sBXutsapwblJPeTHDN28ZOcovE7oZDugvisWZV7B4ducbppb3uXgcmc IPv0PvxCyG9Xfoiw7d9Xtx7a0HvfwPNVbgl4ZLFrca8eZVNvLq3k/ntAq5Ww== 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=1722508845; x=1722595245; bh=xF9m/dypcJJxDD63UOCwEm1cn6P7 L62v+ssoUYQOKvU=; b=mnNtSrXHt9D6ISOGmE7rEnOPtcICD+hpayGmXyrORT8j Mud2OtpcTto093x+f/DU06VYjjD2SE5Pz3EIopdUA/C+4zgjgPG/1vNUjzdVfe+L D0jJzup2NEr930DNfMcNIMdLlXuuQSC1wm3q8gYGUMqt/jbF+VA04ib3qnxhukOv cYLwnJJRg0qUu/D+e09UsXKZMaRv/W8bmjSP73+dPVtp9nj2mLmwJfA0HSBeGJe+ N6gM3WO3kUSC/RsudvWanyLuQiWcBcCK+YMAXZ65WrhUoX/8J3a83U3eWcVw02IA YXftj1IbDkN0TIQuaYesMoxzC9AnOmn6Ko/m7P9lWA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:40:44 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 8027a943 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:39:12 +0000 (UTC) Date: Thu, 1 Aug 2024 12:40:41 +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 17/24] builtin/shortlog: fix various trivial memory leaks 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: There is a trivial memory leak in git-shortlog(1). Fix it. Signed-off-by: Patrick Steinhardt --- builtin/shortlog.c | 1 + t/t4201-shortlog.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 5bde7c68c2..b529608c92 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -514,4 +514,5 @@ void shortlog_output(struct shortlog *log) string_list_clear(&log->list, 1); clear_mailmap(&log->mailmap); string_list_clear(&log->format, 0); + string_list_clear(&log->trailers, 0); } diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index f698d0c9ad..c20c885724 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -9,6 +9,7 @@ test_description='git shortlog 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' ' From patchwork Thu Aug 1 10:40: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: 13750142 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 CA425187FEB for ; Thu, 1 Aug 2024 10:40:50 +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=1722508852; cv=none; b=V5Xa+Sg8oPcNUsf4jCf2LWyG2K/dr7YSFc56Q02lU106n7tPkjz3/DoXnjh32TKOHlQ1i1MoVILccU40ifMNA/M11v5B3yT3p1dnV/jdbT4DgG+FZwA/3SabO3Bf9LZ5DdUSRgsQp6iA/GIk+E2eZxciwUQrMT/zEWB621ef+vE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508852; c=relaxed/simple; bh=o2ka25U3SOcMH+osajZ9PmBXhf4r07hQM/Zk4hnsMNc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KzKZ9embf1TOf1FRT+W+9KfjRiuHW2uo9lxIEdhQi4c6La9/gMLEIAyCdJfuFq71qy3dW0Cg13ddpa5cym3yAAn80g7VnCmT7uCE6NPn1tCXSBnHf75UCIFRN2V6JuT+0ITfQ2bD8QzT6TQjeR7qF26H0papjpIym7pBDVtnKE8= 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=cVnPRl81; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=sI2SSTvW; 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="cVnPRl81"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="sI2SSTvW" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 2D594114ABD7; Thu, 1 Aug 2024 06:40:50 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Thu, 01 Aug 2024 06:40:50 -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=1722508850; x=1722595250; bh=0VfZorWqtF 0PpQXojzSItu80HkmP2/veuIGj8rg8meE=; b=cVnPRl81ja8GZkOfgmB+e/AAER adYztEi7NpHGZP7vq0ZkyG618QEEp4MBF9gI61KvfhZ5xBqTFSSvfkfzLkrGRQce +oFtfFf7+k455+EAib/Pgl0RYusebHX8fxvpRTyVo3rKSWfPP7oq+pcobRJseBmo svd2x1ASQ9xxAAl7JYub2vik3NVVH/RUnrSYxHnctl+cM+WbEe1Ylu0aQ7q1g5Ve F10hnni57ZOhpC2GUFXuSt0j3pEZbx3lgt81wQXUG+1HCgXlwt2JH3tGp6wDbOhS 43Em7FBx3+nynT2JURzq7QaPbG2Fsy5HA4i/z79thFOREDlN0pR83RxC4/aw== 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=1722508850; x=1722595250; bh=0VfZorWqtF0PpQXojzSItu80HkmP 2/veuIGj8rg8meE=; b=sI2SSTvWfgRNyOz0CgMA9IcvV2efeGgWNDfhO2bvTfxP LjByd6RFjXK8cYz1KfnHj3V6pVP9wRjI0ViQ3yRGJO6sYjrlKCKnD89IxcR3zDSb KWr8UtYlsaXOvsSDvHrTkME3J2noAolRbvkiNXFWxnmUch6Pfn2ofF3ErH9yiNrr rfPBAbs/8BAL8yJy0mGag0wrm05tV7ccIVIzgYgyhyIaMYhKDW86OROLa+QV3zQq riWqMd2DkheXitzLN+Yt3EPd6wqPAID+CQJu00vEIBa6MY5ZeIYRvigXUmChuRd8 qR3cUU0GHd/kBNnJRdGiNmZWHw8S2IBPt0S30D9xLw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:40:48 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 432b7f44 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:39:17 +0000 (UTC) Date: Thu, 1 Aug 2024 12:40:46 +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 18/24] builtin/worktree: fix leaking derived branch names 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: There are several heuristics that git-worktree(1) uses to derive the name of the newly created branch when not given explicitly. These heuristics all allocate a new string, but we only end up freeing that string in a subset of cases. Fix the remaining cases where we didn't yet free the derived branch names. While at it, also free `opt_track`, which is being populated via an `OPT_PASSTHRU()`. Signed-off-by: Patrick Steinhardt --- builtin/worktree.c | 7 ++++--- t/t2400-worktree-add.sh | 1 + t/t9902-completion.sh | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/builtin/worktree.c b/builtin/worktree.c index 1d51e54fcd..cec3ada6b0 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -769,7 +769,7 @@ static int add(int ac, const char **av, const char *prefix) char *branch_to_free = NULL; char *new_branch_to_free = NULL; const char *new_branch = NULL; - const char *opt_track = NULL; + char *opt_track = NULL; const char *lock_reason = NULL; int keep_locked = 0; int used_new_branch_options; @@ -846,7 +846,7 @@ static int add(int ac, const char **av, const char *prefix) if (opts.orphan && !new_branch) { int n; const char *s = worktree_basename(path, &n); - new_branch = xstrndup(s, n); + new_branch = new_branch_to_free = xstrndup(s, n); } else if (opts.orphan) { ; /* no-op */ } else if (opts.detach) { @@ -875,7 +875,7 @@ static int add(int ac, const char **av, const char *prefix) remote = unique_tracking_name(branch, &oid, NULL); if (remote) { new_branch = branch; - branch = remote; + branch = new_branch_to_free = remote; } } @@ -923,6 +923,7 @@ static int add(int ac, const char **av, const char *prefix) ret = add_worktree(path, branch, &opts); free(path); + free(opt_track); free(branch_to_free); free(new_branch_to_free); return ret; diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index ba320dc417..cfc4aeb179 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -6,6 +6,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME TEST_CREATE_REPO_NO_TEMPLATE=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 932d5ad759..cc6aa9f0cd 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -16,6 +16,7 @@ test_untraceable=UnfortunatelyYes GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./lib-bash.sh complete () From patchwork Thu Aug 1 10:40:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750143 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 3B5B1187FFD for ; Thu, 1 Aug 2024 10:40:56 +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=1722508857; cv=none; b=U7zN6VeZ7SURfqD01cEEVq2pzr5+cOYDET5LiuSma2/F1uoMNBGYQq1hiW2dj7Wwnvo9Nvx9NG8sLjVIRxrIq5liSDUaWPye6LKgUtlCrbBIe6MuuP7aL1vWLvYep0MkCDAQIit/MHW9ZswZhEHncqykaon1BUFHVJLseYyHt28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508857; c=relaxed/simple; bh=+jyaHBZmMO9HZrdbJUxqO76nlKJpV0w+nmM3zEa4RBc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cObCpVNj/B9xT8tRy3Jy07Gw4WrcNGcGgu81OUxaMFzQQNv4kxxuAa4C/Fu2rm72+6aNZjyCUm4Sya4XSbUcBIucmwie41sghPhnmLPqGtA4qKerMhshGNzZEKUty+LiitBLAbPM0+sk3OvtgsGJIfkCqHd1IsyfOSKCWGMtkGc= 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=aH7alLAe; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=IygkNAcE; 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="aH7alLAe"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="IygkNAcE" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 78BA41388075; Thu, 1 Aug 2024 06:40:55 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 01 Aug 2024 06:40:55 -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=1722508855; x=1722595255; bh=lhSS0S2Ebq Wr2fE6FQbtKEiu8z6y8YnXjZeEeLGk5Ik=; b=aH7alLAeNJTQ3KKLvEW0r32fhk r7k2YnwRZlZgZZMRpltrCGN0bOvDJtcPv1Ym+1+kg+YtQhINsIdJz7G243VHASZ4 TtrYq/8unrUhc2ICFvx1a6QI3kAiFq6zvSyvSj52zTYINh040hrBcUfeRimvf9Cs YhzxAHSYXd0T4BEHFniQGVQyudbe84iq7lj0/1j+yNFLwsE8GBGShA7qbEeYsEjH f7pTywZyy4Q4nfcPkr75TlK1HsCPtfNVKdaWpyZOZ+IseL7j9CNOtqi9ZYpVb443 xInXvYk/+1nxhEd0eEDjEq4qkk4EjF4WTHFwRbbKZw0/9kyA5ZjkQWI7gpkA== 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=1722508855; x=1722595255; bh=lhSS0S2EbqWr2fE6FQbtKEiu8z6y 8YnXjZeEeLGk5Ik=; b=IygkNAcED5TrYcCh8zJfAK/pHwa99w9Q2ilqI9bkqUmG w9IrU+X0eTUAHy8XbHt+BYwE3tQtPj+7TuBBkyBOmiIosvASEIp/DqzC5MqUxPXb Qa3rbyG1buAhd8TcgL6MwMuCUK6IQyrz42bh4Mt63sG6Tvbom4vHqJDbZseLNLJP qCVM7vmfmnkgjL07fHxuaahUdHNdtIosXd/GPrOipoRsrROPRCMDReOdig9wH+He t/RpEKAD2VDU0nTBxrd4Pfr0lLwDmvszrai/AvfWL6oh293bP57FiYH3loLZj89C 5CX+ZLGzsYTR1/1Cngh+nguiXQHZuI25B05tAsuwQA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:40:54 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 27418c00 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:39:22 +0000 (UTC) Date: Thu, 1 Aug 2024 12:40:51 +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 19/24] builtin/credential-cache: fix trivial leaks Message-ID: <788f0bee7bb332e32c305a41a809e82289829e5a.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: There are two trivial leaks in git-credential-cache(1): - We leak the child process in `spawn_daemon()`. As we do not call `finish_command()` and instead let the created process daemonize, we have to clear the process manually. - We do not free the computed socket path in case it wasn't given via `--socket=`. Plug both of these memory leaks. Signed-off-by: Patrick Steinhardt --- builtin/credential-cache.c | 9 +++++++-- t/t0301-credential-cache.sh | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c index 3db8df70a9..aaf2f8438b 100644 --- a/builtin/credential-cache.c +++ b/builtin/credential-cache.c @@ -88,6 +88,8 @@ static void spawn_daemon(const char *socket) die_errno("unable to read result code from cache daemon"); if (r != 3 || memcmp(buf, "ok\n", 3)) die("cache daemon did not start: %.*s", r, buf); + + child_process_clear(&daemon); close(daemon.out); } @@ -137,7 +139,8 @@ static void announce_capabilities(void) int cmd_credential_cache(int argc, const char **argv, const char *prefix) { - char *socket_path = NULL; + const char *socket_path_arg = NULL; + char *socket_path; int timeout = 900; const char *op; const char * const usage[] = { @@ -147,7 +150,7 @@ int cmd_credential_cache(int argc, const char **argv, const char *prefix) struct option options[] = { OPT_INTEGER(0, "timeout", &timeout, "number of seconds to cache credentials"), - OPT_STRING(0, "socket", &socket_path, "path", + OPT_STRING(0, "socket", &socket_path_arg, "path", "path of cache-daemon socket"), OPT_END() }; @@ -160,6 +163,7 @@ int cmd_credential_cache(int argc, const char **argv, const char *prefix) if (!have_unix_sockets()) die(_("credential-cache unavailable; no unix socket support")); + socket_path = xstrdup_or_null(socket_path_arg); if (!socket_path) socket_path = get_socket_path(); if (!socket_path) @@ -176,6 +180,7 @@ int cmd_credential_cache(int argc, const char **argv, const char *prefix) else ; /* ignore unknown operation */ + free(socket_path); return 0; } diff --git a/t/t0301-credential-cache.sh b/t/t0301-credential-cache.sh index c10e35905e..5d5b64205f 100755 --- a/t/t0301-credential-cache.sh +++ b/t/t0301-credential-cache.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='credential-cache tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-credential.sh From patchwork Thu Aug 1 10:40:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750144 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 C62F5170A28 for ; Thu, 1 Aug 2024 10:41:01 +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=1722508863; cv=none; b=SYMFgXivSG52IHobTLK6Zu4uN4d7bwFxIaUHWjVloJPCx9IufFZpg6lwzmaW2XkdtklvwFcZjqBxx2mZTL181wEon559xIa4jiqLGEzE9qSu3NyJbzhbms/WS1GAlnQ5pEJSohMwTTt3Uj6gMHc0VYRvn9AFdavDLb2AaZWUynA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508863; c=relaxed/simple; bh=the81HxUmoAVHf5JbMB32UcDmpzJ/f6f6ORfQW/KCqM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tax9RlJHhqXocGriOMlj+noedkiucqvul1CLZx09m7cZJxgrIOJW296C48utvd5ERK67j5FBWtWCA2LNQgH1tUXNRR12R4dwOmxqceNllsyTjpD50HzaJ1pZzr9bFeIbiCoP0Aki3dxBca8TyOyl4drdxDOzOnrT1Ou2gMj20To= 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=jj9zlveQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=sYMmMkUh; 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="jj9zlveQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="sYMmMkUh" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id D9E761388060; Thu, 1 Aug 2024 06:41:00 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 01 Aug 2024 06:41:00 -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=1722508860; x=1722595260; bh=pfbo+hNIjJ Oa1RRetvGydDVX1nV0SUgcmw3J9gYkWuU=; b=jj9zlveQfwerEyxHZgkiOoay4K 7fE0/uJ9+osXG9uJbg3WfGHqQ1itEMofOf/8z5AAcVFvSCt6Pal4pktsSVN3oiZ9 2sAYxFatqZAnkrPVKTNSZMG2DhQGUeKjKR7M1//Syu7zTYz3m2JwtNOcyv5oe6W8 R8Loup0E1oQcHENXyd3pNCqT23BpihG3+QjCaEZJ/ZVVfeJMvU7uL4O4uEZsKvl9 xuIsk4N7S2ZsnHl7+rbtqyzaq+/pLwZ8MTaR46N2kj6OTHySRAb0I8iUHpXQMfg6 dpHnsjB+6HAWSd/XTJSvij9I3jdy1CZdamMXKLgDAQJYyMq7UReTeHppZICg== 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=1722508860; x=1722595260; bh=pfbo+hNIjJOa1RRetvGydDVX1nV0 SUgcmw3J9gYkWuU=; b=sYMmMkUh4BV6iZD4bSfJz9KQx3kgRY/Jz6cg+kWDVZWg djAhFUWt04OYIviIULDsUdqWVi1ParercUqX2ZWohuTTwub8ByoNtqbrwVDKGJ/U 46YpcHaveBJopemKpVKFYTqry0QD4bx95nC8ZSpeKnwfzSCOiR/HvoQa4BvyBEVk Zxp2j3FmlRGaOQK41+1O7bL23mubBz8y3dnBgP7yT5MnIAhT2VogSR4F7g+6ccNK C9wytEJzQeH4eVVpmXPpqi9cZ74GLb0HyjqAri+QHj+0B+EdbRvMkomKWabyvplV WL3PgO5HSMzBMbghUXB0Q7EUfCIw8YgKrXSCJWfcVQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf 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:40:59 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 1ec928ab (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:39:27 +0000 (UTC) Date: Thu, 1 Aug 2024 12:40:56 +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 20/24] t/test-repository: fix leaking repository 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 test-repository test helper zeroes out `the_repository` such that it can be sure that our codebase only ends up using the supplied repository that we initialize in the respective helper functions. This does cause memory leaks though as the data that `the_repository` has been holding onto is not referenced anymore. Fix this by calling `repo_clear()` instead. Signed-off-by: Patrick Steinhardt --- t/helper/test-repository.c | 4 ++-- t/t5318-commit-graph.sh | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c index c6a074df3d..63c37de33d 100644 --- a/t/helper/test-repository.c +++ b/t/helper/test-repository.c @@ -19,7 +19,7 @@ static void test_parse_commit_in_graph(const char *gitdir, const char *worktree, setup_git_env(gitdir); - memset(the_repository, 0, sizeof(*the_repository)); + repo_clear(the_repository); if (repo_init(&r, gitdir, worktree)) die("Couldn't init repo"); @@ -49,7 +49,7 @@ static void test_get_commit_tree_in_graph(const char *gitdir, setup_git_env(gitdir); - memset(the_repository, 0, sizeof(*the_repository)); + repo_clear(the_repository); if (repo_init(&r, gitdir, worktree)) die("Couldn't init repo"); diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index a2b4442660..2916c07e3c 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='commit graph' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-chunk.sh From patchwork Thu Aug 1 10:41:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750145 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 19F86183CC0 for ; Thu, 1 Aug 2024 10:41: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=1722508867; cv=none; b=Nn+lk4TKj8g3Z/ISVHD06EolcyfsTRquZ04gAlyjsYLp90bUHHmPoMlnS6xN5STYQwmXf995ZIQh/igg50wo7iz0omakQnrvMfXPZ8RQLdv/+t5kyZq+G98Y/+EeJT6dkesVXGgey0RZmqMopZbAXwZLQ1NmK2dtTrbaHDJb2uA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508867; c=relaxed/simple; bh=fI3pKMg5rmabeFEID0rRloWFpj4N+OpKHnQVKVYX7kE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qGMZRJpx3Yd70DYOPI/vGHHEwy8xc36hKVoagQC/tWtik0JslQIFu6AGm1+fs+Ei+rWWJmjvRMKsxB/HzBlQ3HF3IVfAzLGMekRHuiPv3I8HgxkmQJajzsfmxqxasZaAaxxA0HyrKhx1Pz3YnZyW3olKHt/RiE0o2UoUbEH8o2U= 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=K3Q8gf+J; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=oOUl4y5o; 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="K3Q8gf+J"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="oOUl4y5o" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 3FE8F1388078; Thu, 1 Aug 2024 06:41:05 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 01 Aug 2024 06:41:05 -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=1722508865; x=1722595265; bh=QdfFBOUwLJ 5J8xW8G7NrjwOqRyJx3J33+8PiHt+vRD8=; b=K3Q8gf+JIhJSICxwmpgc9Mcqid vSqRzAduqF+RxA+kDsRwRBHeqHbnTM59w+CDlI4IbVaxPPfahMToZ/qRYgG/y9U3 amZuAmZa63nSsExw/iDwbRsM6pgQU+rQZwMVDOu+u2ijhVHxKpJJnoA8aoy63Jrz UfM0w/NlHtSLymEKcX1NsnDvkcrKlMAmvb9aYeQeOih8FxFTXi6zRfn+gpHmvEby JYxBFriIxOmS42TNx1QWlleiwJGLFaRainCsU/XH/k5AIOAfTIXNDp1PONCefXYu JHkeTnlhcQxlYQW92B9T5LaRaNN2q9NiO5UUBjvV0zUUuLBBEHoJYOxRVlpA== 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=1722508865; x=1722595265; bh=QdfFBOUwLJ5J8xW8G7NrjwOqRyJx 3J33+8PiHt+vRD8=; b=oOUl4y5otZE0Pqo5/nVCCLAMM6q7FouJHkTsTcxw5fh9 blvS47hBAbFg+rjO0oHvzu6qDgFlpyY5Bf0ClggBFZNXCp31LvzhMW+sekDWNnJ0 G38VHENLlgDien0tSdDRhFqF7XdoNygJiUbUlwe1Tfqf7dmG2HY80ejUnx6A7oVG tcY+XMExsZt4APsJjXc8UhnYwbz56S7soH/rJUxD/LzneuhDH0XdQsMQovoiFtuY BvBfCftPmCHkL0RUgpU7fsQXYp/V6GYkawexHAL1Oeoeqw0xdCJICp64r/bAbsPh NmeQipoaPFalUsD9azoe6D2rpaJpdP/oLVfoAaoSKw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:41:04 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id d77d6cff (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:39:32 +0000 (UTC) Date: Thu, 1 Aug 2024 12:41:01 +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 21/24] object-name: fix leaking commit list items 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 calling `get_oid_oneline()`, we pass in a `struct commit_list` that gets modified by the function. This creates a weird situation where the commit list may sometimes be empty after returning, but sometimes it will continue to carry additional commits. In those cases the remainder of the list leaks. Ultimately, the design where we only pass partial ownership to `get_oid_oneline()` feels shoddy. Refactor the code such that we only pass a constant pointer to the list, creating a local copy as needed. Callers are thus always responsible for freeing the commit list, which then allows us to plug a bunch of memory leaks. Signed-off-by: Patrick Steinhardt --- object-name.c | 26 ++++++++++++++++---------- t/t1511-rev-parse-caret.sh | 1 + t/t6133-pathspec-rev-dwim.sh | 2 ++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/object-name.c b/object-name.c index 527b853ac4..240a93e7ce 100644 --- a/object-name.c +++ b/object-name.c @@ -27,7 +27,8 @@ #include "date.h" #include "object-file-convert.h" -static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *); +static int get_oid_oneline(struct repository *r, const char *, struct object_id *, + const struct commit_list *); typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *); @@ -1254,6 +1255,8 @@ static int peel_onion(struct repository *r, const char *name, int len, prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1)); commit_list_insert((struct commit *)o, &list); ret = get_oid_oneline(r, prefix, oid, list); + + free_commit_list(list); free(prefix); return ret; } @@ -1388,9 +1391,10 @@ static int handle_one_ref(const char *path, const struct object_id *oid, static int get_oid_oneline(struct repository *r, const char *prefix, struct object_id *oid, - struct commit_list *list) + const struct commit_list *list) { - struct commit_list *backup = NULL, *l; + struct commit_list *copy = NULL; + const struct commit_list *l; int found = 0; int negative = 0; regex_t regex; @@ -1411,14 +1415,14 @@ static int get_oid_oneline(struct repository *r, for (l = list; l; l = l->next) { l->item->object.flags |= ONELINE_SEEN; - commit_list_insert(l->item, &backup); + commit_list_insert(l->item, ©); } - while (list) { + while (copy) { const char *p, *buf; struct commit *commit; int matches; - commit = pop_most_recent_commit(&list, ONELINE_SEEN); + commit = pop_most_recent_commit(©, ONELINE_SEEN); if (!parse_object(r, &commit->object.oid)) continue; buf = repo_get_commit_buffer(r, commit, NULL); @@ -1433,10 +1437,9 @@ static int get_oid_oneline(struct repository *r, } } regfree(®ex); - free_commit_list(list); - for (l = backup; l; l = l->next) + for (l = list; l; l = l->next) clear_commit_marks(l->item, ONELINE_SEEN); - free_commit_list(backup); + free_commit_list(copy); return found ? 0 : -1; } @@ -2024,7 +2027,10 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, refs_for_each_ref(get_main_ref_store(repo), handle_one_ref, &cb); refs_head_ref(get_main_ref_store(repo), handle_one_ref, &cb); commit_list_sort_by_date(&list); - return get_oid_oneline(repo, name + 2, oid, list); + ret = get_oid_oneline(repo, name + 2, oid, list); + + free_commit_list(list); + return ret; } if (namelen < 3 || name[2] != ':' || diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh index 6ecfed86bc..e7e78a4028 100755 --- a/t/t1511-rev-parse-caret.sh +++ b/t/t1511-rev-parse-caret.sh @@ -5,6 +5,7 @@ test_description='tests for ref^{stuff}' 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/t/t6133-pathspec-rev-dwim.sh b/t/t6133-pathspec-rev-dwim.sh index a290ffca0d..6dd4bbbf9f 100755 --- a/t/t6133-pathspec-rev-dwim.sh +++ b/t/t6133-pathspec-rev-dwim.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test dwim of revs versus pathspecs in revision parser' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' From patchwork Thu Aug 1 10:41:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750168 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 65EDC18950D for ; Thu, 1 Aug 2024 10:41:10 +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=1722508872; cv=none; b=F047CeCi3pUIoYf3xd+mLraMUf1poxlLyixcyTSkhCcZaIG8gs23q5ApKu4HW6nKyXPku2ROggkiygsc2l+be8z2Sncb9tINCRwsvOPss4Scn2ZtyBgcMNu9sz9ZlEt5si/VMD67BjucALGYLUwAw+fC4Bvyz75Yj/igwtANOF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508872; c=relaxed/simple; bh=62NryDJYZUWsvg7L0DXbwUoyYGOY9BrT4l0/hNASRww=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KYbzAIUi3gjlPFerOJ7BM91DAm7cbogC9MoOutQbrTSxyBup6s2aMAHb2wlEnraShWyjKadPgfFa5fq66MA+3X7gFwk7v+WnDxgTRDD9ZGGa13iCvJWxgSvddis6ivvyjcg5mM3YEe2kvkVl188zWX3/2YRLI8Jyt0X0FKOK5Js= 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=Z1vYSi77; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=krCR40tH; 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="Z1vYSi77"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="krCR40tH" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 9DEED114ABC6; Thu, 1 Aug 2024 06:41:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 01 Aug 2024 06:41:09 -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=1722508869; x=1722595269; bh=Ccknd61NFN z85nSMNkkpCFxRymCswArm6L90MBrRUtE=; b=Z1vYSi77mpY1CUZ/Z8iYFwqMoi ZqZi9EgCdFYusdnenM+rV0tkMNZX6OhUK7c9fstmiNDfpn+8l/OgGYjb7j1cVOHx VTHJJmK7/KrcFjXgOcMOQbATMZFHM+nFPwZD5xOSXGlHRMEieDOftuIt58mge3gc M3P01vc7Cd3dHyr2NBUTTl+eE79IrEHq/+UCNYgNF6taAdLhXOileGYkcIo2QMVO Jc2SGXx6we8JCm2OgKZdOVdOEg7HfNis+ZE0f130D+Nf8evrVLPR+qLC0lxMziUr L2IdStl7bphp6ZQn3+z27E7l0rhDsgJljZUrg+iEHSlCZq9/LZg6G5477fyA== 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=1722508869; x=1722595269; bh=Ccknd61NFNz85nSMNkkpCFxRymCs wArm6L90MBrRUtE=; b=krCR40tHVcBWAahKtMa7GEdeIUzI1iwvuTtE0vq7YnMV Jtd9nzmCPnLTUpzzBQZeCK4SBTbiDylvRaxsxBy7r03NXKLZQFnjycVz+ST+myD+ EvjhoHxfstNNbkDCOCp0o68PdrD19wB8FQO2T4DDXgPo5fgs31fLMh3fpsiEgT8h C4eLuU7lRF+sinoztOhA0WolUQCcKsClKZnCyyBJPFQlxWay0zq7ppYmt8I0lDe8 th4jcQ0mA4oVoIFdtD8JuUK0kiz4CEMxJOzPDt64xT4UPwhGiwju408R20Laljz6 SPmJKv0/jkMD9kEniOAWZz2j4YD6D+vzypuTQfXttw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:41:08 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id e4edc6b6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:39:36 +0000 (UTC) Date: Thu, 1 Aug 2024 12:41:06 +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 22/24] entry: fix leaking pathnames during delayed checkout Message-ID: <8cae4c44f4ef5bd7686d90ecc051a8650da7d057.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 filtering files during delayed checkout, we pass a string list to `async_query_available_blobs()`. This list is initialized with NODUP, and thus inserted strings will not be owned by the list. In the latter function we then try to hand over ownership by passing an `xstrup()`'d value to `string_list_insert()`. But this is not how this works: a NODUP list does not take ownership of allocated strings and will never free them for the caller. Fix this issue by initializing the list as `DUP` instead and dropping the explicit call to `xstrdup()`. This is okay to do given that this is the single callsite of `async_query_available_blobs()`. Signed-off-by: Patrick Steinhardt --- convert.c | 2 +- entry.c | 4 +++- t/t2080-parallel-checkout-basics.sh | 1 + t/t2082-parallel-checkout-attributes.sh | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/convert.c b/convert.c index d8737fe0f2..61a540e212 100644 --- a/convert.c +++ b/convert.c @@ -960,7 +960,7 @@ int async_query_available_blobs(const char *cmd, struct string_list *available_p while ((line = packet_read_line(process->out, NULL))) { const char *path; if (skip_prefix(line, "pathname=", &path)) - string_list_insert(available_paths, xstrdup(path)); + string_list_insert(available_paths, path); else ; /* ignore unknown keys */ } diff --git a/entry.c b/entry.c index e7ed440ce2..3143b9996b 100644 --- a/entry.c +++ b/entry.c @@ -191,7 +191,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress) progress = start_delayed_progress(_("Filtering content"), dco->paths.nr); while (dco->filters.nr > 0) { for_each_string_list_item(filter, &dco->filters) { - struct string_list available_paths = STRING_LIST_INIT_NODUP; + struct string_list available_paths = STRING_LIST_INIT_DUP; if (!async_query_available_blobs(filter->string, &available_paths)) { /* Filter reported an error */ @@ -245,6 +245,8 @@ int finish_delayed_checkout(struct checkout *state, int show_progress) } else errs = 1; } + + string_list_clear(&available_paths, 0); } filter_string_list(&dco->filters, 0, string_is_not_null, NULL); diff --git a/t/t2080-parallel-checkout-basics.sh b/t/t2080-parallel-checkout-basics.sh index 5ffe1a41e2..59e5570cb2 100755 --- a/t/t2080-parallel-checkout-basics.sh +++ b/t/t2080-parallel-checkout-basics.sh @@ -8,6 +8,7 @@ working tree. ' TEST_NO_CREATE_REPO=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-parallel-checkout.sh" diff --git a/t/t2082-parallel-checkout-attributes.sh b/t/t2082-parallel-checkout-attributes.sh index f3511cd43a..aec55496eb 100755 --- a/t/t2082-parallel-checkout-attributes.sh +++ b/t/t2082-parallel-checkout-attributes.sh @@ -10,6 +10,7 @@ properly (without access to the index or attribute stack). ' TEST_NO_CREATE_REPO=1 +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-parallel-checkout.sh" . "$TEST_DIRECTORY/lib-encoding.sh" From patchwork Thu Aug 1 10:41:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13750169 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 D7B1E184541 for ; Thu, 1 Aug 2024 10:41:14 +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=1722508876; cv=none; b=liy/+UYB3Dh80TTGhqUDG7RK1gvKFVNgSS2tR+kLWVu786ct0aOuzlTrfCuxQTp0+hp1PMhH8kKdHrsy834qg1tHT3Zi1V6d0/Zi9qK7arY4euhqO27kpmmKfx1JTPWyKyS3V31Y+PwRQwx6SOtsHJs0hpfs3FsaEy/ePV2EbgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508876; c=relaxed/simple; bh=gy4dXV2eFwdHK2hreYaKysAVvS6LGnm6V9v6Oqe9XEA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XKi2I+ypnIQGvP7HGJtB56HIqO4IhKztdlaOBld0yCUMd9MfFWxNP3m1ZjCmrQ5RnhxWu+V7Fa2CsejwLL6UszMCn2BrbqSDqhzaTvGQKlag8vzjrfnR4y1zW3D3VFwS9OVds59pkxumB7mGJm5D0LhSrzZmDpen2Jf52zaBCwA= 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=OSZ43eY2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=izty3Kbf; 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="OSZ43eY2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="izty3Kbf" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id F35DF114ABE0; Thu, 1 Aug 2024 06:41:13 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 01 Aug 2024 06:41:13 -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=1722508873; x=1722595273; bh=UMJsJzgmI5 bJkqLVv28i9wRSKdIzWD1ntABe0QYafeQ=; b=OSZ43eY2VldE/t4zvmchw6GOG6 z2iPPA/vWILzNuItSp7iWx+Tvt4NVqtWyG3uxZUHvyzojK0CHlfd0RUFxXW8FYh0 x8m53au5/MFG5tACDfJAaH0YdajrC1Ymtl1aAJJGopIrezsxC6q1OiH5xbBLEoUv yaZ4ITpnUlQSOHEXvbndBsZs414UQ8bsLQXcJHW9S/KEIlYPyCKfRitSoh4SqTKU p1qZll1p3s9tv7LXyF/+ByhxOfQFHLxFdM+ZmETWWMIS3ExJe37kTvUWdSNtTByp bCAe0bE75XuLhhKczZbRR9yCxDJUXIrRgoFBVCZQfErESkTOv3rorrTl4v5w== 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=1722508873; x=1722595273; bh=UMJsJzgmI5bJkqLVv28i9wRSKdIz WD1ntABe0QYafeQ=; b=izty3KbfqCEONosIIraOZ4wRbLy8i04KKJpd2AQnFWwm dxYhI7dZCUdtyi0FDcGaC35dekGh03pUB+w6hKFMROioIXkvYmSyo3hcknp8kRqx U6ruDWf08jgb3svKyQ8tMlCWMyZ73V8ejVVeejl9smYmpYvGFIlSqSQ5mxlRdQug ViASCqurS/c7RcUuGVOR0WFXr9L33ahgNMcYTPxMgiqWnOq5xqgjqF/iUs/CEGxn nFMwWOhTS8bR3BMVSoJLZvtVP+VO25Zktw6YiMH0zKYtwoY6qLDGfARhNohTPjjO h5olOlw9x2lkXxwP3Q8+pm5sCDwqtnq8HgLLKvr+/Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdefudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:41:12 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 3c8c1685 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:39:41 +0000 (UTC) Date: Thu, 1 Aug 2024 12:41:11 +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 23/24] convert: fix leaking config strings Message-ID: <5d2bf0f0f3d05f402df87588511b91c8246401c3.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: In `read_convert_config()`, we end up reading some string values into variables. We don't free any potentially-existing old values though, which will result in a memory leak in case the same key has been defined multiple times. Fix those leaks. Signed-off-by: Patrick Steinhardt --- convert.c | 12 +++++++++--- t/t0021-conversion.sh | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/convert.c b/convert.c index 61a540e212..92ce04c406 100644 --- a/convert.c +++ b/convert.c @@ -1050,14 +1050,20 @@ static int read_convert_config(const char *var, const char *value, * The command-line will not be interpolated in any way. */ - if (!strcmp("smudge", key)) + if (!strcmp("smudge", key)) { + FREE_AND_NULL(drv->smudge); return git_config_string(&drv->smudge, var, value); + } - if (!strcmp("clean", key)) + if (!strcmp("clean", key)) { + FREE_AND_NULL(drv->clean); return git_config_string(&drv->clean, var, value); + } - if (!strcmp("process", key)) + if (!strcmp("process", key)) { + FREE_AND_NULL(drv->process); return git_config_string(&drv->process, var, value); + } if (!strcmp("required", key)) { drv->required = git_config_bool(var, value); diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index 0b4997022b..eeb2714d9d 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -5,6 +5,7 @@ test_description='blob conversion via gitattributes' 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-terminal.sh From patchwork Thu Aug 1 10:41: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: 13750170 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 33E55184546 for ; Thu, 1 Aug 2024 10:41:19 +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=1722508881; cv=none; b=WOjl0QtxNTh9icV8ARhxvPXoXi5kHc8Opo/UW8CK9H+3FB7gJEI4bIpq9XFhtcl5ozFcEV+5Xn1X/DYNbFTfKjTFetHynlITttdnNZ2vYIcc9tF2su2Xzbhb81d1nnY286jmyWugdUgqh0UI/sN/evGnWqv8c608qKKqPyG30gI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722508881; c=relaxed/simple; bh=HuPUtDMYEDAJHUMOvCG3UvPEm45Dt45ZQopfKebsk/k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IjT/V2DUoJKSAjuHhm7qK04QPRlcpSGkRGtHFpcmuJCVi+Ptfg3JZ0XtELPZ85XPonbGd0OC80oeeGcAHllz0sYfJKiE+9JU2h98WW66w9vje4bSfgZmsgEOfldM9SI6P5IqeMsN7cE1eZparmJZMsTNGAV8fXFn0h80pvxBUjk= 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=in9d/SwD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=YSMvOPzf; 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="in9d/SwD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="YSMvOPzf" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfout.nyi.internal (Postfix) with ESMTP id 52A93138783D; Thu, 1 Aug 2024 06:41:19 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Thu, 01 Aug 2024 06:41:19 -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=1722508879; x=1722595279; bh=29RrOxR8nP sUVeCZjA0JrTrauARyJgRLh6JPoY0NymA=; b=in9d/SwD5R6JVwUGNS0lpcYLU1 H++clqorRm6UfPfpO03ZB6EZdnxO5AbFYnq1UOQsBrDB8bjJT1VII7zxUWjJjtIY CUwMl4xghV5snU3ZhBbAv2+c/7bhFBswYD9qFqFSe5f0vGs6EKiBSiFvH/Uq5jcB ni7f7TeDlbacOKkBMVfF66NsZz+1fa7a9pLUmEzVHiNnAY0TuI0QF2EB2HAp6DZH CkdNh/Zp/1cJj3p1qCV3qTphr+7B4vTKXhtSC1NtZvSE13LwkvuThBiPr5HjVhew zghcT+EzpjgKDr40LbPmwBsXdP5X+KuTMnqw3wjTY882H4wSwGC12F9BEuhA== 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=1722508879; x=1722595279; bh=29RrOxR8nPsUVeCZjA0JrTrauARy JgRLh6JPoY0NymA=; b=YSMvOPzfBdEvsOiTJbo3tjgiZh+M3a8Cdy6/LtuMcF1z TS+W7YGPwekkp5JfptbDw8EzC6sSqOYq0NFRq3qhsu71EVgj3GYnRjACPNFrx6rI euDDPM3+a+T2W3czf7YkxqT8VJ6OAeei/E+X/teZrL71nWDdcRPWkfbrBti1CSSa k0L6cjxztKhMpHq0zFgu24fotGozW82xnYaurtsRdWRHyPOgouIrI/TSgh/F6Zxf B2OEyIlaxWuUs1xTDBrkdZChBvk0kd7m2JDaWuK+XgEyTbn2wNjKXCHUOfqBsN0y X9fcPoxqEw/Bl33wDBd80gI2a8NwAecjk0uV8bNj+w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeekgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Aug 2024 06:41:18 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c85d2e8f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Aug 2024 10:39:46 +0000 (UTC) Date: Thu, 1 Aug 2024 12:41:15 +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 24/24] commit-reach: fix trivial memory leak when computing reachability Message-ID: <6db1829c79401009c81cd34322274e4196114fcf.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: We don't free the local `stack` commit list that we use to compute reachability of multiple commits at once. Do so. Signed-off-by: Patrick Steinhardt --- commit-reach.c | 1 + t/t3201-branch-contains.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/commit-reach.c b/commit-reach.c index dabc2972e4..02f8218b8e 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -1227,4 +1227,5 @@ void tips_reachable_from_bases(struct repository *r, done: free(commits); repo_clear_commit_marks(r, SEEN); + free_commit_list(stack); } diff --git a/t/t3201-branch-contains.sh b/t/t3201-branch-contains.sh index 800fc33165..6e587d27d7 100755 --- a/t/t3201-branch-contains.sh +++ b/t/t3201-branch-contains.sh @@ -2,6 +2,7 @@ test_description='branch --contains , --no-contains --merged, and --no-merged' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup '