From patchwork Fri Jul 26 12:13:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742724 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 4687DA3D for ; Fri, 26 Jul 2024 12:14:08 +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=1721996050; cv=none; b=arMMQxKFTvD0nrtNI6ZuVfDlloaiZcYYsH3P6mgIokiRlrRjakzCBR9PDHYA1UMlOuwbBjdpk1xXl09eUhCs3wzRyeQYD78CuYhfcjIz2/JINEd3ZhZBNuBLAUqzFpMDBGvUET19oYBZjzIvDTMdEfVE7e/UEKXbA4K6+8tPnO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996050; c=relaxed/simple; bh=2d8b9LJmbevrXYxtFZhIEGUXlA4IFeHYkmNk6mSGnzM=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rzRsGCfDkljHMQoVF2Bl//adUkhvgmOzrAgvfO0BhfxzqVF+yEC6YHluTeGB39SqC8qqAJr+LC8aN/qsVsCOF6DbecguS+nEeQVwcBp0omIvJePicXFDg3xFh26ohd5iCLWs+gIyL/7A6FjzFjUFbr6XfqfUWehv/WHFOE/aTis= 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=jE2+Za71; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=a8Ek1pNR; 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="jE2+Za71"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="a8Ek1pNR" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 19387138063E for ; Fri, 26 Jul 2024 08:14:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 26 Jul 2024 08:14:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996047; x=1722082447; bh=TSAq4/bUnD B7UtIBwCvWyVdHqn9Jg3Y9WCHO5y8tkU4=; b=jE2+Za71OXbk+GZJNnwkVGl185 25+MoBBs+J/5wJDgcpWkIAbH0Dq/z3SPb6wDtsZmBQxlNa0+RraPYBhnMJaJQciX YUejxvaGNtKsv7sDD+SKuQ6ZklHV5mAC7UU2FDuyNBXUys5wT5mFKcwvkQLxqfAM R9IOVy8CMaqCaNKcbt7DhTHLBU+RCw3xoeNrXsqq84AP6OPQq2+croA+uZYZMRBU h2PJxq0scu//Tva59Qr/Kp1YQl8/c7TNHkcTy92lKnwfLCMtWtd8CNaKsj3XhW0A aEuFHu5SzISR7GGbZFss4nOCjHX3zBibivrcCKch2hvybhAMjUwxZ7155OjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996047; x=1722082447; bh=TSAq4/bUnDB7UtIBwCvWyVdHqn9J g3Y9WCHO5y8tkU4=; b=a8Ek1pNR4aJrunSzz/SxdGBPBb9cEmBj87kkgzzlIA/y cZf6VGZL/4sV3n0VlBROXp1CNL5zjXo/Dvh/7FZF/GJNRFFpjiVd0OHezD2LieeB DnDH42Z1zoNGQZtRr3JsQ+uKdU668/zqRxOWApK5GNqi61eT5qxEk9jai1XyFmC+ 85eJUIOu5M2If3dOkBbKUCS0byPeAR2J+Jd0mQEN8zK2M+dalh75cVMWeVKbHM+2 BvycLtvEmyxkZhMcuAeD7t7yoqofeAqHcP5tY+/2zIP9QqzfiEa8JA/+Vrw8Dq63 KtPLsxL2fFjXj+BHlPIM1oAB+YmnH0ykyv6UmyNI/g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:14:06 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id e6abcc89 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:12:46 +0000 (UTC) Date: Fri, 26 Jul 2024 14:13:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 01/23] 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 Fri Jul 26 12:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742725 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 4F2CF179950 for ; Fri, 26 Jul 2024 12:14:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996059; cv=none; b=SI4KDgCKBocvkpX364hd5uQzfRqJpyrOqdSFHeDJo4W3Nufq88cBWq9zip8KTzAGksU4wsKqDOougMJK3SDySwopZ6wMwEY4a/1SOaNKGsoJkRlnbWO2NMCrQzkqTv0273KF/YM6XqhAqHPecffsC/1dL+FKgjL9uzxBMkrD6Zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996059; c=relaxed/simple; bh=CYL2nIhUuoX11nLiCJF9sVpTTkby1xJzR7eWzM0mh6w=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FGflXG5p5JnDyLcjfDQMQKFZHM82dSXy9Sx9lebGkBsb3lu/9gWKrOMzXbmRpj/J1epGASFWbKKy8VbteIZQWm3Aa/k/51827dvB85ZGyqaSUSQA/LBEFV3kMbv5fdebKkLmRl3gDefvXDKYVPwvW117gfeElScIrT8FWpoVjeU= 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=oR1kY96o; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gfLf8uOG; arc=none smtp.client-ip=103.168.172.152 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="oR1kY96o"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gfLf8uOG" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id EC31A11401F7 for ; Fri, 26 Jul 2024 08:14:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 26 Jul 2024 08:14:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996055; x=1722082455; bh=de/Tqk5T35 p/Rvsk8vjQivE5hrs4kAlD+4fYL6eD5Ck=; b=oR1kY96opQ3S3L1dFk16ryUp3Y WoIZWsp7sUrgZ04UYeCuFZLuU6VjpXxXCQpG8cegRaDj7L76Uce1wEF8uEF7HlCC Y9EhdM+vAtoKlt+4Ac0PDV+/w3JoSwncs00E+XP69pm8MiZH+AUcNDE5Z3u94OyX lxlU4VJQyW0bjroWYtUzNwGN9r8DX2tgL7cf0V3sBoWGWUg9UYGv41vKsN5BXcJd 77Q0dBk3HvdD7apJJXVKyz+z8ENEwINmuRcSCzTmFBEriLfD1NbYxvT8V5u+4eG+ K1MGKCzGNGFrQ9bY2Jpp2BEfQLvtqmJr9yU6Hxce/w08jspxGLeiNRG4YEVg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996055; x=1722082455; bh=de/Tqk5T35p/Rvsk8vjQivE5hrs4 kAlD+4fYL6eD5Ck=; b=gfLf8uOGzpj4EfAGsYKAq+nuPOspUk2I7X6lx4llBdr7 ycEs2pPJGYv7ZKqDBARRgO9gx9CAy3FPtb30xwE3CA6cFmMa0jpu/nPVi921WPBp dKXoljKgzx8tKS4lziuxa3K7S/q4iyRWEQG1W4v46Ym+TFrijJ9DBk/ueBEY9tTd Sg1tzsbwmiBhvC9yTwsYzpAY+mpP7coujZTxzw0OJ46rsptl0IB1ozZtMCPqC1tX Izj8TJGSbCKjWmRz/aXyNgolRWOkPzqGGp4IxyyJdJ3v6DWefwJubGM8M2GNoxTg D9IlghUi9M3I+WGX3Mt63vvV3/SrNPuPcM3A3T0hQg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:14:15 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 9471a9c2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:12:54 +0000 (UTC) Date: Fri, 26 Jul 2024 14:14:10 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 02/23] builtin/log: fix leaking branch name when creating cover letters Message-ID: <4daae88877f2355d6a3960883e7b3f15cf738cb5.1721995576.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, then 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 Fri Jul 26 12:14:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742726 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 A5E72A3D for ; Fri, 26 Jul 2024 12:14:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996075; cv=none; b=QyM78jsWaZCi3c3cU3/SNUs3LCrNYkI5uTYuZ3+lIkg6DwiDt045dzwDyLqIQlaa/hBhBqL17L5d1AFLrRG4ojuqwijiEI7OrevpB5Q3i7Ztjrp5mDc+cwTYlPAD7WYdfuWpjkVw8fkAIcstbT/dT6+h1UFgnuMHoG/pOQVd0Eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996075; c=relaxed/simple; bh=Lc1dzyvbtE2d8hVcLI5MPOrPJzlNDS+w26EiTwMacsU=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Oore+1ZaGJSUG/E/uI0Dyk2EQnwNWwyU/ik69W3DG5TN8pvL0Z6kwLVAjXot7WiR3G7TlYljH+8utdh5fXa5VBU5s6GPJ3oqZ427oPVRI8/W1ElVCs2Yfu9mse9s4rwzEp70fArimTpX9Z6dSHdK+7nrq0akGYLSNpNBXsg+2nc= 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=YLjywYMP; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PF6VfZkH; arc=none smtp.client-ip=103.168.172.152 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="YLjywYMP"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PF6VfZkH" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id AF1121140257 for ; Fri, 26 Jul 2024 08:14:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 26 Jul 2024 08:14:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996071; x=1722082471; bh=ZkEp3QTdeO GFUWiZHkip1/hGAYKGZjRcogD+AOCX690=; b=YLjywYMPOafsoQtIKFLDGk2ViH x9HGhU82PMIvSyiR8I4Y2cANwnz0k6cy8dvsDy8cC8uJcYfx3ZNboCM3HCOy/TjO 83mnqEJZ8T0AqB/VB7bj3ob3S8eGttIovpDK7eFqC9SQvfGEparzDZ4mxf3PxOYa lwpMfoM0QO2DeEEcWnuoSUhDrfWcRzLp9RHZ8OccTWm42gus/hc3pzG4nLTixhRp +FefszpWR0nv2CE2dElmFDhYK9cueJu1QNK8Wi/bt/HPtMtcDSVKmuagEu9BaOv0 ceuLOnQ8lc2yYPDdhQ9UuyLADhL8ANi7xBSX/HfNtEIE9F2tFNxNgUJeogsA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996071; x=1722082471; bh=ZkEp3QTdeOGFUWiZHkip1/hGAYKG ZjRcogD+AOCX690=; b=PF6VfZkHv++hVLf89x/Ape0UPyNL3ouftamr3baQaQpu 53euPV9S7kiUl5k/6cVltVGFKh98VIIxg9NYlb4BVO+q1D3XWlyD6oqLlk0yL6J+ ZepGGPDoHHXa/fihWDzHT7LtreWxPmNiKnN4QXLlO/MO91uNleBku/OPsLvGELk/ fCGhxdxEQXe7Y5bsoKQamYiliRe+6W56tSSohvsFro0+VrDfF6WkRRnFTpQyiB10 lT++EBHWSZl6qOHHwoojWtYL40gUqcOxehfLxyJFZLrtDMoF+NVHQKxUi4pASUSO IE1uYM7WGToUtjT0AZ8932liTx/sKp+C5MA+eYN2sw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:14:30 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id b13d68b2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:13:10 +0000 (UTC) Date: Fri, 26 Jul 2024 14:14:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 03/23] builtin/describe: fix memory leak with `--contains=` Message-ID: <08a12be13c2fed247d6086967e7a3f03fa6519e1.1721995576.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..4c0980c675 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 link 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 Fri Jul 26 12:14:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742727 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 87483A3D for ; Fri, 26 Jul 2024 12:14:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996089; cv=none; b=r7TJcItxUXa9nARBdmhrNOsNFMBNf7uFqYt+FbRF8MW+tCqWbgAwtc39fbVrAVF4hQqc4Uks9FzoOdzsZct6P+oJOyifKowNkMJMP6juNlXG+4Qwz63o41ym0f6nYTSb0DLY4+HqB/NaJF4ErZmZXpPLUFgruFffjnLoTn4PF/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996089; c=relaxed/simple; bh=xW4OroKUNWqQB0XJvvPX8BCMHn228mjod+yCCtFOPBc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Bahw/IOqDOX1ICwRHiW3Vvg/gDOTMW5s/bHNKCLOCpQuCA4fdSrrbJ+lv/cpD7ukCipUgWbGhw/s8INosw93oaqMoEphOMCI3Dw9mHc5tz9mqELkuqR1UU8nHGrdbOZqaLFf4nFua6N+mI24gYG/TAe+nIA9xvA4CbkOvepeArk= 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=bMWAjoOE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CKzmr79f; arc=none smtp.client-ip=103.168.172.152 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="bMWAjoOE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CKzmr79f" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A62FC1140284 for ; Fri, 26 Jul 2024 08:14:46 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Fri, 26 Jul 2024 08:14:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996086; x=1722082486; bh=L9X+j6oqlF 0JPaeEfO1fRYTaDQdPNGkAmU8Y+aRPhFA=; b=bMWAjoOEZSAhX7NrEo6cjpgy/8 TWUWXf0WojZvCzK2Es5VXZCpUVqedERoH5wFUV063/D8dLArX1LLFZ109biqp9Iz ZfysIPKLwaY3N7+Mt7dT2MCaVGmazLIsW2Ii1gfvNaT00EskxuMLSPRcCmUlXSNG IvLrxGk45YxAfWLuHJ6567VfY+EBW+fR8Vdjrs10wpGC/wdyan6BcE3wv7DtLdeI HNf8py+pfnvRwcp433dUggsXGzeNhAJlmJGdyksUadJaNhXjy7r/ZuGdqv7PnehP yS9T6sBw04yxey38dyR1si5c+u87ZfaYs1vzv7hhfjCIdOzmx5wLVR2CkjYA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996086; x=1722082486; bh=L9X+j6oqlF0JPaeEfO1fRYTaDQdP NGkAmU8Y+aRPhFA=; b=CKzmr79f+/nsqKbIhV4Iq8+ejhGLEdVijV+1IwGqX/EY dMf8Swz9Gl/Rg09MpRYskN6bUo+bAe85ZCASOUM8tSB9Jvh+AFNnuQrqHIkS1OLs 1qYYmeHs3teurcqK4J7lRk089PyiYsM1+AcxjFUne0IGhzUTr5soAhJU8xr95Nju lr2pCvP9c2aZ+blvmU/YCol3rCuVyDhKYVzwGXy1nJ0dpYi/e8eNgFTZKfwFmYkV 92ekP2WTFIj7uryxLxHf/HyF6w7iOo5AsaEST1TQfyfov5rtiA2AF6EuV0uo1CU5 ub8eueznqYT10uEA87YIar/+39ZsylgcouifUKaZGA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:14:45 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id f805cf68 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:13:22 +0000 (UTC) Date: Fri, 26 Jul 2024 14:14:33 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 04/23] builtin/describe: fix leaking array when running diff-index 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 running git-describe(1) with `--dirty`, we will set up a `struct rev_info` with arguments for git-diff-index(1). The way we assmble 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 4c0980c675..3b61aa1baa 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 Fri Jul 26 12:14:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742728 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 59D8A17B42C for ; Fri, 26 Jul 2024 12:14:54 +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=1721996096; cv=none; b=Vu1eG6YhFxQdKh7+xP8W1gIY+EdGN+Lt7uFNyFJsrKIkvD151to8Tr+/d9KS5fhSWPXalJ7fRwqUnx77IYg5xPZmKFd66tftcHQcIBDzeh8LBV8U9n7feXxqKVTM2SkuTPmwjon+yNdvRJX8tPdMb2vNcOBb44KiFkb18VJllRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996096; c=relaxed/simple; bh=wTVBpgL8hBzwwDS290Fn6HP17/IJMNREl3gY3Gkq4hQ=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=j7NGe9/aQtuJ5F8exEOTBLkZbYW8Q9/b63QGoi0CPNXm2cg2NmZmdHL4FzWNkgC5aXODD7afzKnSKhRnOEAHAMyoXUohocBrNYAP1mGcLd9T/OiAIegEu+T3LdyTXRkBO++MSoficFTjsrY20cgcd9lDT9yVoU8aOKIwOvN9IXA= 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=Ejm/w3hB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mkRqE+Sg; 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="Ejm/w3hB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mkRqE+Sg" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 8A21313805F4 for ; Fri, 26 Jul 2024 08:14:53 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 26 Jul 2024 08:14:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996093; x=1722082493; bh=XH+Et1wC62 cOQQ1C8Q/p91G450lqlwQR0X9M0+vlIlc=; b=Ejm/w3hBJA5EA8jPKjboNSoVQa dzaMibC6Z5M5XFtdS+9+75v8ECgYHIqgIE+/phNuBNMrrOC47r5kzcQtUzomUhaF Et+MvAM04azWkC0epSNuqwh21eaUvlDtnXctc+J1NAKSs9ETtGXJ+xLQn61zSNst E8/hy+BKEzQrnBxMrdllSR6nz06W6q+3WfgcbFeipqYG5XgVDHl1lnNjMUS8wCOY y6MxmojcrymMQS3sCI+Ts+GEazhFMaGplm/ztAccYxeAZI26Pdcflu5mwVxgwrZp llKmD8DAEaBPS2desMxhclxtOZZPsBoDLEXSVUR2kqPFxXN5TeYYx3gXSGug== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996093; x=1722082493; bh=XH+Et1wC62cOQQ1C8Q/p91G450lq lwQR0X9M0+vlIlc=; b=mkRqE+SgA4QuI5q43mHBMb8MWvBmJVBu8uOOXE+UHjIL UZKwv+wj1F56VKobiqfsglNI5byhgapChlLM+lWt4sqefrv6QMbKrVqYvbtTq/oN 8Mmk8Z0PgGcyNzlMHh2Jl9h5RbNZpRLwmpiQkdEcDLJ7iB/wVlEg4okTyHc7LGt1 a80fzQyp5cQixkywnfZLAWHskTZJUo38QNh2ketoaTnjWx2J6Es26DSeuRNU/r/p PUbuo0porRQUfk9YTrvmugQDzqtVPFsm+U3lNbWOat4+LI2u1nlV/JsJ4O4VXNTV 0VM4imczK7AFXu7GTqdVOBIMuOHms8MbpaORCFfMhg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:14:52 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 0cedb960 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:13:33 +0000 (UTC) Date: Fri, 26 Jul 2024 14:14:48 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 05/23] builtin/describe: fix trivial memory leak when describing blob Message-ID: <8aba7434bd3350ea98ad055c3f0acd2045b96960.1721995576.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 3b61aa1baa..aa5ec8d68a 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 Fri Jul 26 12:14:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742729 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 98B60A3D for ; Fri, 26 Jul 2024 12:15:09 +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=1721996111; cv=none; b=TdZEFrOEXwzPFrWlCbzgkzkt2GHfyH2A/glmBXaW9p8cc/zY7M+vrIyY5MsFQV8mZpN4wWTJPJQ/5PnQhelnpfhWVr77YFCeh+449AbcP18fX+QuVOkKx4+WOFRsRiTbUa+IEisuVBG5b+23hc+Ytvn3gLQwai84AfEsq04royY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996111; c=relaxed/simple; bh=VRXNDcGJ4HWe6YpfCm8xFsjceQTMYKgLp6F2Q1PbZOk=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HKlYl+pg5FQAQM0G8ZrT2z1gZlnFL7lVXVg/NQsXbNV94eGvDzfsPFAyxf1NQP1I4+7UgZbf26X+szhInoc+C1ZkPWAfAWXM4wcE2ZU+xWtPFzyUyFUtkSfFmsSU0m6QmFXC1SEkdC3B+bmglx9Y6y/AdmL3dp9/yZAnGqUo0XI= 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=fGXwInUN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=g/H54iRb; 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="fGXwInUN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="g/H54iRb" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 74BBE1380532 for ; Fri, 26 Jul 2024 08:15:08 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 26 Jul 2024 08:15:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996108; x=1722082508; bh=/xVE2Lesc+ A1JM41zcuE8UgGg+Y6uhpj1DZmanjNan0=; b=fGXwInUNhuSwcnFdL9/2QYyVmu L4Hc4949y2xe7ETxNzQTWKgEU1az8l8j9na/a1vorpnvHqIl28IkwEnBkRtGJONW FLzztsN3EqUkYN0WrLDUida68tJfwOysQU8ivTQbxP6hhR1IlygZMgpF4QHh94Y4 imJzE+nm6jf6r3YbzfyPPEBLJ73C1k4HW74l0hla5OBXfIue7MFvojqvgnWhqcGQ QxxgV+6GR8RDANA4f52kV8wyVvPwWYswmV4AHf4p++ffdeW0KIdPMeBXq+/QO5cF TB2Mkl18CVE86zb6lX4tUV37V56U63yzSjERpEiYSJC4nLT8+JAhQ9Yfltow== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996108; x=1722082508; bh=/xVE2Lesc+A1JM41zcuE8UgGg+Y6 uhpj1DZmanjNan0=; b=g/H54iRbuXxzLM1eLqwHkVedXPgiO5DgK+5VRyGCTxdq jXp/9+aDZGOdKZ5eM7otF34vv3GaSxyzmOBU3Cii8u//i+Jg3QMq2CJgX00q4n50 CawdpOAOg9NNf+ur6NHtReQCagkax2bOdcRwVbEK1cqhWzfsAVSJ2et5iKvVNo/P /ZmiujwwOntmWYzjYfSfmwioWUmfwkDLLx/kLBsyr8fQRfkwXP+ZvEUo2XwCZMwd uMWwbanOKxrOKKd555Z7Ri6jMEb0Uj2tbeXbvnamZXGlCARdhHsJFWoObn7M1bwB Ph6HDLtJYAIWSLZtJH1Ml9a78vFFh9a+R8i32CaRDA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:15:07 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 37a551b4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:13:45 +0000 (UTC) Date: Fri, 26 Jul 2024 14:14:55 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 06/23] builtin/name-rev: fix various trivial memory leaks Message-ID: <088f730572f0f5aaa8f9640ea35a4687be9094ba.1721995576.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 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 Fri Jul 26 12:15:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742730 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 7949CA3D for ; Fri, 26 Jul 2024 12:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996127; cv=none; b=ndWTmBLe/bNQwWiBhpuqL8I/gqY0EnYFmJl62h0WnWj3IRXbioaDG2WDRJKU60vjdw65v7RfsJzOuV/QDEyIsO0nvWCSq3n8gPuCRN32nCC/0VeXIktwoKaAqswg+NeD+ce+0mxT/85Dye7s+uIfydIktBLFTdkrmdHUBkUMZ58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996127; c=relaxed/simple; bh=96RY2/13WVoW+HZPFdCIAPrpzKngSKBdR//vRHgvrm4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KWp2RwUPo6yZyPd3SC8i/dJsJxe/UXlmNExXGquCY6QSC4r4bQupMJC8E8j22VPvekyTj4x8r3mg96Kjj2LN8g98Ysf7UUTwvg4O9r3SXz+y9WzNwq7X6ZCGZqcdMTNTeaoFtcmkt0LpE11QfdjrdlffkfEM1sTBtB6jWuoQgDk= 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=qEo4d8wU; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=IkoPn7kY; arc=none smtp.client-ip=103.168.172.152 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="qEo4d8wU"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="IkoPn7kY" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 9340A114028F for ; Fri, 26 Jul 2024 08:15:24 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Fri, 26 Jul 2024 08:15:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996124; x=1722082524; bh=eldXnVMZlO dgZ0DRIRRo/jb7RZ6Pkx7UrWNTf8iyBlg=; b=qEo4d8wUanyofDEbfCMCAnGQzE +0cGxiqOxiaJazqvrIMSpIS8fZ9ObtHYRCfHDgJEc72gzySCV177fDfGvwgJ3ySi v65NYLIOJ6xu6lELg1PVL/H3cVPNesoi8/47DUXcEG4k5mRJYjuh0vMNxaMl/OYR rWI0Mn28oI/VjNtDt+NK2uwZw9PQdAUOZLAaXQpycAz2Vh4020DSdR/Uyv3GxIzO izILhvKWBUZadosSwqhtBZkGZdS1WJ2OQfrKhAN7jiaAsCOxQ1ZD9S1CbWN9fQf4 +OqekvbxpgqOGYCrIvtRwdHqW/5G7fG+2K9ffXIwnYBtmiTKNxiAkeULxiiw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996124; x=1722082524; bh=eldXnVMZlOdgZ0DRIRRo/jb7RZ6P kx7UrWNTf8iyBlg=; b=IkoPn7kYNo4VwKH+K0gmeoWw8L85iZJ3bJZs3kJhT0dt gIOHYUFzOseBrLeZ0PQldVbKe8A7cydkcBWLzV1XoQ+6OgYZKZR0LvwrnHoRPAdb 1W821nDmuF3d2n7/AmbSdW+SNNGk5Rd4pna1yH6eLXt9p32EwYZaC8yJSbwa5/sP WnYa6MILD/aUYdqG/zn0CuHYV/I0R0Lrnj4bA9qa84OLg0fPy9K4U/tYqDYVgY5r gy7Hht4fgkggL6rw6G13FCLl/6TjJh3TSR3AQDWQyDb/40miHrpwp6UKg4s36iwD MrwIzjrIr3jgzOvEEBMEGXAd7HS7LASKx88gufuQ0g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:15:23 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ae7ab6d7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:13:58 +0000 (UTC) Date: Fri, 26 Jul 2024 14:15:09 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 07/23] builtin/submodule--helper: fix various trivial memory leaks Message-ID: <5220c91bda7bc766368c2925499e5d244a03697b.1721995576.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 the submodule helper. Fix those. Signed-off-by: Patrick Steinhardt Signed-off-by: RubĂ©n Justo --- builtin/submodule--helper.c | 13 ++++++++++--- t/t7400-submodule-basic.sh | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index f1218a1995..5ae06c3e0b 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2269,6 +2269,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; @@ -2278,9 +2279,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, @@ -3135,6 +3139,7 @@ static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path) static int add_submodule(const struct add_data *add_data) { char *submod_gitdir_path; + char *depth_to_free = NULL; struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT; struct string_list reference = STRING_LIST_INIT_NODUP; int ret = -1; @@ -3200,7 +3205,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 = depth_to_free = xstrfmt("%d", add_data->depth); if (clone_submodule(&clone_data, &reference)) goto cleanup; @@ -3223,7 +3228,9 @@ static int add_submodule(const struct add_data *add_data) die(_("unable to checkout submodule '%s'"), add_data->sm_path); } ret = 0; + cleanup: + free(depth_to_free); 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 Fri Jul 26 12:15:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742731 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 9ABE5A3D for ; Fri, 26 Jul 2024 12:15:33 +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=1721996135; cv=none; b=fgvWwuyvJ5ZYndachKss2Es6pYaUVv/WTjX7R3Ou7p4CO5uDifP3lvdFf+TqzLDqKlrFANb5jeF6k8XLe9wJnkw2tAMV3T0kccRe1HY8AQsmBC44UX3KzEXrwC0zZI9GMbnAQ+GF2+yKHopjwP/Uz2FAL7/p4K0eNW34mAAsVSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996135; c=relaxed/simple; bh=1hdQqrtx6rsU1Gfxt0kfKvJDVWXPRD4GJeNLtvOoMa8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SwIDTSf5wFOkKC2GOgwcQcWAPqdrtT/N4Z4qKDWGva6kG36XLDvtYPLGGICv/VRgfCklOnBIylLY7zgiTSXMtWW3o5cSQtPbSfVj7i45vDtKgG3Lda0mqvlw8KHEjvWrzJkS5XtKOMTs7kGzBaOvcbvC9SVomGQ24BDlEO3h2Ds= 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=ZnrU9PTP; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HJlwFEdY; 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="ZnrU9PTP"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HJlwFEdY" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id ABDFF138066B for ; Fri, 26 Jul 2024 08:15:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 26 Jul 2024 08:15:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996132; x=1722082532; bh=dTd9b77c7A S6O/4xOhKLZyUx4c6zN8HIApT6K9jumxw=; b=ZnrU9PTPD3p6yLFET1cKd1NtJr OOoQbpPk5567iqBs4/2PYNPDfU11snxuGO49VU2mGWfPvW57PHFa2GlkHmgratud kV/oC5Zo/gVnzSR6+2YfgKMwBxoh0dOnyHTZcMMVzgiVcJLch7p+f5S9h9xk+Ik/ 0yrqE12t3dFe/x78ZvDwR+xx7u1N0b+dAkvzbR3O2851641ifEW+El7b2p50ViBS iRWvkPnsfclpbWMw4+snhGcDWdOaEzQeT4TjKBRphuwLeVmcoyw9vnD9WXbpkq9b WpX+mlZUk9vm8Wr1Z45u2l+1vQRI3XENWWkaLdOZ157+L/I8g29qi4vzLYGw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996132; x=1722082532; bh=dTd9b77c7AS6O/4xOhKLZyUx4c6z N8HIApT6K9jumxw=; b=HJlwFEdYgnZWbzhTgWqx4hMVPMtBIOL2c05drk1gNYSZ rqUuIJFVDCWuWOzcR++2c5dXD8UQjzRm1SRSrvBmTezaI2+TTSi3CWJdB2EjT2Eu HOmGxb3lbouIYMwhUCoCA9IQKOZY3NJ91ZlI9ybt/wE0pCRdfnDoQj93Jeng9cZt ycEc7MDDFdjnX9Z2PlM37VT223K9eSFalwHTgVEe42NCksI8X0YTzIgk4x3khTay KqISpytRrwzmMTlY0mqUp/REgb2cev34w5WPfy0AyGTQUxmgRlTeAu/r+qUubN1r fTdhFdS0wIByfb09AknMDf4pqVwNsoCPirp31Ig1TA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:15:31 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 62138296 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:14:11 +0000 (UTC) Date: Fri, 26 Jul 2024 14:15:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 08/23] builtin/ls-remote: fix leaking `pattern` strings 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: 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. Fix those leaks. Signed-off-by: Patrick Steinhardt --- builtin/ls-remote.c | 11 +++++++---- t/t5535-fetch-push-symref.sh | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index debf2d4f88..500f76fe4c 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -47,7 +47,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; + char **pattern = NULL; struct transport_ls_refs_options transport_options = TRANSPORT_LS_REFS_OPTIONS_INIT; int i; @@ -96,9 +96,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) if (argc > 1) { int i; CALLOC_ARRAY(pattern, argc); - for (i = 1; i < argc; i++) { + for (i = 1; i < argc; i++) pattern[i - 1] = xstrfmt("*/%s", argv[i]); - } } if (flags & REF_TAGS) @@ -136,7 +135,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((const char **) pattern, ref->name)) continue; item = ref_array_push(&ref_array, ref->name, &ref->old_oid); item->symref = xstrdup_or_null(ref->symref); @@ -158,5 +157,9 @@ 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); + + for (i = 1; i < argc; i++) + free(pattern[i - 1]); + free(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 Fri Jul 26 12:15: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: 13742732 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 8EA1C140E34 for ; Fri, 26 Jul 2024 12:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996150; cv=none; b=W41L7fY6xVLHVv06RAR3I/ChXs1bCBeODPSsbPhGeBEb4/6i3AIYMC79Yq8iZlCr2ASIBgyoCM7OhqimVio4/yUlQjcMirXzsgunYalUyEK4PbUx3pRHURx4HtajCtmXD8eXVEZUDLhOpZz5e0LoNCcAttESgOLoMbjtUlEdLt0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996150; c=relaxed/simple; bh=GZnj2b29E/8TXk1PNN4gnPdxaFDeeF132IYSeMuC6rc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=I/pD86K5jGJdjED0MnCUnE3sSdHAyHIC9iMMh/nlppLuyPzgtvHfDJo9h7anC+Ii6ShQcWvG+IhllFaGIi7WLwikFcbUQNfXQQt6/Kj3Sqr+tJyI+VaZhRrCYIUL1Skd8Trbo80tm59a99oaJq8yFF5DWpKMKJaqy4yleXErmeI= 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=Sb653LOm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=rU1QdmvM; arc=none smtp.client-ip=103.168.172.152 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="Sb653LOm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="rU1QdmvM" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 537EE11401F3 for ; Fri, 26 Jul 2024 08:15:47 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 26 Jul 2024 08:15:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996147; x=1722082547; bh=1LTNsuOJcF KJPqFpRl3qzga4ZdJJ4fZSTseYyUj7wj8=; b=Sb653LOmR388j/ISbcYFTRK5yo uLw6YGLFz4oiFf0IGFuoYv/pwX4jr7vCa0NxLFL176uV8Qa8qkFHgITRs4MSyqKK bzjIiM6/Se7JipNVnmCdper65p7+reoE1SQF/FZ8xxwoEJ7dJyl3Sp6veKN10jVk IPuUF8xJdK21CqKjsr2oIPmAL4W46svobV5g55AlGAKndxq/wFkPZro/tdHZboDM P15TBeDy295M+9Xy5WU4dUG1susLwPOubQxPK4/fY5ChzNsh3PmvKPeQe0XjcTZH dmTKgo1UIeBhcXiScbM3dC9yT59jkRVUO98dXoeY4v7j1p2zHZEqlYam7w9w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996147; x=1722082547; bh=1LTNsuOJcFKJPqFpRl3qzga4ZdJJ 4fZSTseYyUj7wj8=; b=rU1QdmvMuVwDB7V+K04o9dETnADIGWFXLOx6TChnkTyZ w6SWQgI8FEHUVyTSqDU10ynbtyv3g3I7MkrgjYitMFlBAXw7PukmOBN7pqymjEGY D0DNOjWRrDMy7VxDd9MT6HpMggo1DqBMIMgoxfsUzdRHG7IesJGioSNdN7jqvKIN LbNQCsldLXFje5mVbFb1Ar8rwZkzwRVKI2CkeOARxB+08xAhoqSFlUi9kbFFX6Zb ETUxOL84DsTYSE2+XX1ETvTqyoXvIRJb7xvutSFA/GP8F5Kf5LUYKyNaFEF1LZ6b CK6Sl/Zy8IAx2bDKnW/OhFcdU+ENJ8TLRgKX8N/MQA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:15:46 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 6a7ce5a2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:14:24 +0000 (UTC) Date: Fri, 26 Jul 2024 14:15:36 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 09/23] builtin/remote: fix leaking strings in `branch_list` Message-ID: <6952fb2ff2cf453de39b63883a716a9f09cab7b7.1721995576.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 Fri Jul 26 12:15:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742733 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 EE69F1779AB for ; Fri, 26 Jul 2024 12:16:10 +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=1721996173; cv=none; b=Dg6ajkvAn7i0d1ZhOyg3mo/P8hdqp9r/vyN7bdHXQqur0pafr/mzThEN57LQrzXDeAltxXMZ+B9Hb4cYB5CDAS2Mhsbbr9U1ilZuvJeVNtjI+m9aaiaZj2IIvc5BbD7rnsBipKMykI6R1d7pZh5c8Ckp6I9e8uKP6rI+vbcm/ag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996173; c=relaxed/simple; bh=ifvIybvW+8+mBUanM2WBANyiE3EyJeL+dDXMFMlHTT4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MqD8VdsP99ByAbOdeMVz0t77qDO+IvnlXMXlBvIMP3zHw6ng1ZKaZFSwA7wTgJ39KA/1BIxMqNak2kpBND2RZkOiJMH0vRvj6U6y8V0VGw8Zpjk+R/5G0QvF3abtAkSN65bE6No/ku0IBIM0Cyy9OcqVB4XZIx5vxMvcSanPjg8= 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=FhBpQpu/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=u9taFOvW; 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="FhBpQpu/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="u9taFOvW" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 1BE90138063E for ; Fri, 26 Jul 2024 08:16:10 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 26 Jul 2024 08:16:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996170; x=1722082570; bh=2CDH8UDvpr PAQeHxye1SDi7LHtIhY7wNuJlLKyJX494=; b=FhBpQpu/ySibQOrsqgPfzxeFZd 644+PK8GsYkU6wdRpOTfIeHcJQisDJSoP107BM9egsJmTXLRTWHPLZMMO+dYSOdr vlfU/rRGSwSgsjww4OfJeZoy0DRkZ6O4fz+NZaNmnWzBspv9vf1cAfPfzR0w2jO+ DSlfJl7+h10/RypBgEk3Na3qs4pjNfW1lhZoDh1iKGLw1c5cf8xsNJWtB3h8Nb+e 1JFVZTvRpq1w+pHuleO7WwnxvUMCLO12HIz9d04Nwa75ZU4fKaczorKkcBM3iUE9 WWT5iRvbcRzrMOF2wrgfc+CDSbP/hADQnL3POBcOubDrn/kJF1+CXrcURxpg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996170; x=1722082570; bh=2CDH8UDvprPAQeHxye1SDi7LHtIh Y7wNuJlLKyJX494=; b=u9taFOvWEYghLDSiIt1a1TrhmLaaQGQwYHdpWraVqhJu 65jhD8N2O0xVC1r7oDUzfqTr87RZEIWSRVPfbUduvOmcLiwR+/Zp5bDx0pqOr2CS W4lLa3ZhabmFrO+wy2W2TC14t7dCDPfPhhshNgFoXsOFigVn65FPs2e13QUDmf03 EUOquRud5iWzkNClaV+Qsg4Swryh/EVqoJ+liPRExKzZ9LJO2JNEMl5dpdMYP8Dm KejYKZyhnPZoTd6AOUy+H7cSIbFU31P6seGM2mLxtMsVLkC1wRuKkdkPntdq1/CK 84QPpnk7GBKhg1xPu4ryUzNufBwbk6m7IT3iCkshrQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:16:09 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id f2d9530d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:14:46 +0000 (UTC) Date: Fri, 26 Jul 2024 14:15:49 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 10/23] builtin/remote: fix various trivial memory leaks Message-ID: <8bedcfdad80c19dbb98e1407e4cef985a066c714.1721995576.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 Fri Jul 26 12:16: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: 13742734 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 16E73A3D for ; Fri, 26 Jul 2024 12:16:21 +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=1721996183; cv=none; b=EvLPNpIEF2miuFGC/jC9kiBQLnlPcKXiPlwbqPlFgJF+pHXLDz6dZ3grfM63YNkAtj+UUCdcxDAituOlIzkf3pKEf5PUiK8LSJhyx7sdB3iFIWE2yO59IRxTE4taxvhU7maSP9uKyX4jwQLLoDWmbOcBF1x2t8DBExU+1fxM07s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996183; c=relaxed/simple; bh=WgO0V5fGsyLgT1c1omRgff6xxCugaXOa5zRtefyWaVM=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mN7LPhucBXl5Z9Gj4pDX6DqfnJj2izKtesCRddgyoYAoqbTM+lkFDMUaARbYhjOMMqdPb12auL8ujJUMDFdtWBfp7KGPuvuy3Ea7zHkUZm4qutQuN06JIKaQw2P1WLIAn6zYbDRRfylxQK5tJ9gwwEiWilcNcwciUTGEs/n2gng= 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=XnkxU+4R; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=dQCID0GI; 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="XnkxU+4R"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="dQCID0GI" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 42B4813805DD for ; Fri, 26 Jul 2024 08:16:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Fri, 26 Jul 2024 08:16:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996181; x=1722082581; bh=f6CX5wCoF2 mM3a0adFOCvXdcDzOmI8zntGoaSeAwK3c=; b=XnkxU+4RpIoNE/oNDH5poh5a5T /BKQgz+7mFgP8ROUb+F4loi4WTOnV4+d9gSWXmUf5Ng0oRwUGMBWImeH8RbJZily Vx9p8EpFhXfcR+Qsgs3fV1wbCo5EgWhcv4jBcDoUSHsKSGrx6WssaaPmWihcuHd5 VF54hlGLW6n24eIXK9IwjOTTu/bhv2lqBVQ4zOHKk9rR7pSAtR97zAgJcNzOl1O8 3rwUUsyc3mxg+NazyECqnV97qQNwVdDu6YU1ltIGeg7w69r8Ao+d8tfxHSB3gGY/ r/hebGe84TJo0pJxCIM6HJ4oT1hRpbBkAza3diQRkFVDhStRDby8y19a8qug== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996181; x=1722082581; bh=f6CX5wCoF2mM3a0adFOCvXdcDzOm I8zntGoaSeAwK3c=; b=dQCID0GIIIuyFNV8dH+P81U8i7z9B1EbmZ7+6RQkQQMH d01R6/AFQ+juHilMKAD33KgUDj86Niug4ftzWivUyCPKqFucBTCdf/LjJr/KEMN8 S9TD0Myio41dRpHTYspkOn7LXvkexa0q8XywFX5aPD99kPveXX4wzta1aZBml3Q6 ua0+eGHsMbSPhaRmL7POyadqMl3QK2g0Vz7NIZC8soxbqOHtwqVuxKyyASLFbKCm dqSHK7Nz10VgGfjuIlMBKduyVewSUnQFwtcCIHGxTv+AkZTjvJwBFt4U3gTj1xSj TXTxv79c1S8qUaoG8Eq5rSu1W0/Im2zNDg0xY8ayZA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:16:20 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 5a1e786a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:14:59 +0000 (UTC) Date: Fri, 26 Jul 2024 14:16:12 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 11/23] 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 Fri Jul 26 12:16:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742735 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 D0664140E34 for ; Fri, 26 Jul 2024 12:16:49 +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=1721996211; cv=none; b=oIvrrXpBB8VwgaRVUkybCz96AKXesDTbkyd0pXMvU4be8Ihe10feWM7an+F3CelLeZH5znu/6kY2vdJBT2I2XOmlTAV621p2zBL2fkJoBVHQKVCpYgoy37p9DvBUqvO6vyIFU/S2j61ORZREfokeBo04j9K+/LbdMhCdgnpBma4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996211; c=relaxed/simple; bh=GSUGuR4biMcDrRRdCcZud78q1/tkig2F/k1lHDkN1Hc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mQGlmkw1IIT4xjpHBccwLNeYNGzQBSkRKr8LyxsyHsuNmuQ28pd0S2Pxd8wBr3SyI+R+WhqgIlLns2KtocLZ1nUNWAuRbGR+y5cvINLDbwDBumuZoEcneU9s0chWRTlI3OS1vP+r79NLXKwmo1xrHmRkyOvO2VOE6Vy1n/rqfOM= 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=cjpSPIlT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Guf6PASS; 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="cjpSPIlT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Guf6PASS" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 5B22E1380502 for ; Fri, 26 Jul 2024 08:16:48 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 26 Jul 2024 08:16:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996208; x=1722082608; bh=nXEeyZmaW1 pOVsP5vw1xvpi4WPMR64kx+0BZA4V+zcU=; b=cjpSPIlTJDShl94OdMvfcM726M XCzRwfQ3vmh4tz8X+lb2VHVOVe78ZaWOUMpUPgC3wMprWk1CaZDmMxQAR84Cwtow IhltdTVPzcvtjRCOsuqDQ/fQptzze1yYhvi9UygTTWb1QqD6oKuq6GQPW27hcglM Vj3qgeEh8XJZgNsTEU7ExbmjM/Pr4V6HLywwDo7ilvQs8109TqOgZZXDz2mx6iB3 9hOMOD3m/YwYjbR2F3FS8X7cSEOJjZIz0zmEc3Yd19LMdFogoXAYtbpkssUEzrUg g5k1nk9hwDyrMC8XifQnfxmSH/J99lm9tBskHjpn3J2cUl5GSDlySPA/EMjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996208; x=1722082608; bh=nXEeyZmaW1pOVsP5vw1xvpi4WPMR 64kx+0BZA4V+zcU=; b=Guf6PASSpZsqkFR/6hyqdIH7zjhCe/TXSuJIxebkGEN9 UcZ8ErGLqY2w3jJ+FpxZHLamslbreVf11UgQvqdQTHUWSCRnCluNul0/r2IOhCbt 0RBD7XjyWT41w31QxzWKO0dazwSHP+zl44UquqZbkiejK6UpLSPw76h1q7pKoFjP sDP1ppjaulxtUIEIjTezokIuOK1efAzBDtCrybFz4B5b0nh4XLdit+7OYaxpB6ur mWTh87pB+5TqEKvsmKZC2PSxTtHBFfdyPeVBUAmSfeZlZXBKMHlYrFXvT+akvMpk hc0BVI7FnlrtR4a6b9UzM+VzqzS841y/KqQXOP+a1g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:16:47 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 809716d7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:15:26 +0000 (UTC) Date: Fri, 26 Jul 2024 14:16:27 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 12/23] builtin/rev-parse: fix memory leak with `--parseopt` 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 `--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` fielids 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 Fri Jul 26 12:16: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: 13742736 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 340D913A3F7 for ; Fri, 26 Jul 2024 12:17:07 +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=1721996228; cv=none; b=b7DyMVCbvpmjSq7LLmhe9JSp3YWzf4EXBXZp2m3Cba0L5uFKP7xzGcfEklvpsM28xXdBXyzhN0eNyQNKzA1sZeCf0swfgV08tqyY/953J9kc4JMNK84+3xZeUah5Dp80BKsyoS6yESI1JfJHUSRDXsMOyXFYNh+ChX7tbpvEirM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996228; c=relaxed/simple; bh=ULg8dQdApo+E5PHQqXHvqZyCaYvNSp6nEXZ32Dtmorc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AppxAbaSNnfkAFfU8HWKpPe8zXM0s1Lqi6ek9kZOVTh0pGENTorFIrNXRp4ZU/2gW+GVbcwl77uS5z/HFNUKlF0n9qYD1+kgm31yfMWIpJfWLOVN6td5NhK/jo8r7/yxvgRsffHYmRjilkE/rGH3UE+H2+3z4J33DdxawaTU0P8= 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=nqHVV4Uy; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=f1/L3peq; 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="nqHVV4Uy"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="f1/L3peq" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 7F2B813805DB for ; Fri, 26 Jul 2024 08:17:05 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 26 Jul 2024 08:17:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996225; x=1722082625; bh=wLZaitSLv3 HXiKArvRvLrBAC+zItTN9WZ+pj1vr0YGI=; b=nqHVV4UyBk7SGARaR4iFEona2L fBnryNwY6QIa1QKj9b3JrGY05jxwGND8oi2aGvVn5PBKzeiap9A370hoMqCm3XHZ xpXfaFiShCdi+mBBJA/7mA8k2dfVRRnax5rWXX9660fbkMPwcYivc0SVpPMMPkGV 5H0gql4XysGnqFBGqGTGt6Cwvohgk/EZ51xt5Wa8WBHNvnjHmQvBSB1s/4Lr4jHa Ss5F4S6/LBRs3HidVUk/VA8veWWzUWcUtkg2aqnV7dGFetbAcJUBW5/i0bV+YB5D 7QSbt04yAqpgi6scE0nTfkMBZWp1f2zA8v0YxCDq/aT3yxbGeF0hiKg8lOAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996225; x=1722082625; bh=wLZaitSLv3HXiKArvRvLrBAC+zIt TN9WZ+pj1vr0YGI=; b=f1/L3peqtVWXL7YfNIq7C/lqBGaMnd+uIhf/+Zg22M6b 4CDCQzlwcadYrx8rGEW48l5GL9twXq83dU2U105QOmsdKdwoP5m3I9WIL665lVII QmW6KbpizmLkJcbOvRMEFpuI9v9hb8ID3sD/IByQtjwXrkDnJ7kSxRw7B0t2u7op uTD+4mzDqufSfJlJFlVNj1ruLv/zmHYpbc++9PMKE8B7zr/25DM9dOXVQozOsdze yAyx71uyxYtjsRxoBErx8kBLztBVxlacxfFb6+FqPa4PIpXSkfmXnFHdFU/q9U6R ioYjOBP1qfozCjntnGZSnUAxD5fI+SIV8iLQd6J8Pw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:17:04 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ebc90a87 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:15:43 +0000 (UTC) Date: Fri, 26 Jul 2024 14:16:51 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 13/23] builtin/show-branch: fix several 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 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 Fri Jul 26 12:17:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742737 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 52A2713A3F7 for ; Fri, 26 Jul 2024 12:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996233; cv=none; b=JF6bS/vayd+AXX2oKIUizU1uoIJ2nBMmeM0mkgh579ToxzXkt5HcaycKVoJLHluiEWVQioDUR9SL81AmuSxuxRHHHlF2/kh15MAZjQi/qxOseCbAEgrbyOC0wb1O0Pe1ZXof+Jp2q9bEgOAHJY/yvSxUnCcERXWFq/wot81Nrz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996233; c=relaxed/simple; bh=y0jbpnxT3zUpcLATAakWVPuz21nDBYhyHHSNUW76sxA=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PUOc3JV78Vn6uRAI6pCb/ZH7+OBKgQsOnD8QFSwWFg0GPHYcbIfRChc34hToqPFiXrL34gKR+V+ED4fkpKITyldnMhuqrwjbJ6Qid1edL+s/XJ4fmoymB8nNKPn+J2KPqw4Sip5r4PZQNpxkse5PeTeLjYKTYngFyDMQq0JV/q8= 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=Oe7P8kew; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GClJ1fDy; arc=none smtp.client-ip=103.168.172.152 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="Oe7P8kew"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GClJ1fDy" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 609171140254 for ; Fri, 26 Jul 2024 08:17:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 26 Jul 2024 08:17:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996231; x=1722082631; bh=1k1kx29KgK Zr6HL5B9zFn4zcX23r0/SWmaYFkUu2VqU=; b=Oe7P8kewiHnGs6gmSXLpHOvnv/ F3eTt9P2oREo1P/Es1La0ILmzo5NoPCDawM+VlKGY34XB2uCvc/tGevATFN6wxWt JkgkymBm9/SlLilKvewjnSwdAD7bRYbMZUhOHVO7e1G2hOcplFSQ92SdPpeUuVDA HjGoUKHdYyhsvVHjdRy5tcF+9XUzlDl2+ja9TAib1KaL41XZ1qfIgLZ++1hqhtwL VCVut5x8CGaMVe50JpAC4LB3pkEJ85o+M0kZZQqRxzu/uCVkq7j/Wwuv/lbNexHR TXHyKWn0atf/QbxqE8w1Apszx/vtzMwERUz+phJEM+IoyFOVj6jv+HLKXuew== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996231; x=1722082631; bh=1k1kx29KgKZr6HL5B9zFn4zcX23r 0/SWmaYFkUu2VqU=; b=GClJ1fDyvO/BAYESMJmFKavrw/mT35og1nHprzIIDZQh EPNtuC2Lj2atqiNLBb6Cy3P2QtjU3XHQs81UTt0j0vigV9/PaJZ9G972sPBoEOwn oySDiDTgxijgNMGvhkQ/mxwiXE2B+2X9FHFpm4QjnKL6zOhpXn+s/lT7TorHH9O/ ja4oo137j4y9n/Ruy+3dylvp7erZ2vefVz0PE+Iz6/9Bx9bVn6arnNhKHqpAdOAr loPgrKgjf5nWIgujGWtvOLfka8HgemSDGJp6QV9sbPKWcuFR7ysYlwHY4A5p3A/K /ePt8zbjfFYylr0WSuHdWHB5ykL5DeVT7RWMHb1yzQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:17:10 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 46bd3714 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:15:51 +0000 (UTC) Date: Fri, 26 Jul 2024 14:17:05 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 14/23] 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 Fri Jul 26 12:17: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: 13742738 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 D7FC813A3F7 for ; Fri, 26 Jul 2024 12:17:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996251; cv=none; b=MKCjeAGVd2jYFr/hN3jVCdQQEud+PMle+2vYMzUyEAWe9u6CKZ1MZOVqJK8V0a3NMwSXbha/Vyg0HkF8cdfmT4ODQEmgWIkYf13lM2kflT9Wa6g/QpkmWuZrAKNVL/xNqp2M+c1WDrS1W5PxUAJT0GqwiTMrnhn6cGpc0UlNU4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996251; c=relaxed/simple; bh=azKWkYdVqF00t5KYj4MiWzSIbHKMmXsNteULm2hBAFM=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=g48P7eGaRcPuyF+oAz24AlbN/kAcl1HdU3ZVQrGxBJts1+UWllsj8VmTOzbYLKddJs36OWavErf+ADTlzzgqYI8H+4NfZryOutksy3iQiNfI9B5yy9KaRqkx/3kI1FbJdTGCKGSaCtjnGvwfhnpcaYHolM6fq95MzFgEMoyY+pM= 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=b776kiFe; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UU9OzDl9; arc=none smtp.client-ip=103.168.172.152 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="b776kiFe"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UU9OzDl9" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A777911401F7 for ; Fri, 26 Jul 2024 08:17:27 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 26 Jul 2024 08:17:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996247; x=1722082647; bh=Igr5CR98E5 ah2ppCkz6NIEDJMXMPQaj0XlyJqtEe/dQ=; b=b776kiFeeuIEYAF58wAn7y2OLU Udv7sAsu6D+tqoOlzQuEprfgaQpX2sAGwvG7951p33hqlgc7SGNcDI5TibMoNFO5 uZQsAJaygSbefQH4JQkDiNIhK9s9fcPNhagzYTENSvvkh8U1OKYQdsDZ9rKOaHhf kFuAwPR6wtOU8yy4A/3sK6o+rfVDi6yi3XwWELd4sBbNNKyF4u+85WoqGNTVLq4q QAueMCuONiEQJQaV9p6HYpDs8vijxIWeyNsFItKFB0XC+51k4Ar6WalPKMIuKcF5 dnrDpU1VrForp2SnQ8HoDs/h1f/14T/DyEWbmfdm6mY00DTfDBoahbuwVxjQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996247; x=1722082647; bh=Igr5CR98E5ah2ppCkz6NIEDJMXMP Qaj0XlyJqtEe/dQ=; b=UU9OzDl9+BMykyY8JbmfebtthUEL0zg4Hb2+d1oXfSIM +nF9c+osKT/IPOTnOh5tykAWFbRkUYS9J/d+Q4dBu9yKB9uAX5Dv3SB58o+dUfu4 6aepXC8PylRVM5drM24sDt0AinaV8gojkpd/bJa9xM1nDVrKM2NUsPOToXhGOUXZ 1+bzRVdaCeb6fuaH0hoHMqVgJNA5VdpLZD522O3u8avRNgXdWJyYg6WlFt6IaaTw qtuTgbO0vfIPopzVz9d0bXMnvZV5Cd4NwToTbEjhGwd/gAajAlm6VyHDHyR2m2Qf D2z+UHACxLdJNRBkV5jOvTZb6tBmVpreIESrsOIb8g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:17:27 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id e56b563b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:16:04 +0000 (UTC) Date: Fri, 26 Jul 2024 14:17:15 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 15/23] builtin/rerere: fix various trivial memory leaks Message-ID: <6d49645c0f82420388a8ca3522b48982fc2fe92e.1721995576.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 Fri Jul 26 12:17:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742739 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 BC8D2140E34 for ; Fri, 26 Jul 2024 12:17:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996259; cv=none; b=LHkyWnNUOtFf3RQi6PFy27oTCo+oWdlcRSqMXOL9r95g/GVVqtvyVaZlNhvjAuy3owOsfnuPCDqySObkitoPMZNhxFKlQ/nOg4a48M2NdVJEd7Eg2fShQTsE51ao51QQqg1lE+7c1BhQ8fK3sMRpaEfkH8eG7YmzwG3cfQPTG0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996259; c=relaxed/simple; bh=SzelzelH37sEk5y4Aw4DTz1I3Yz893enRljT3RCFEkY=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Dwnpg4jmkNvyKIrvxOkT0JEUi71tM+cHarAgCwenz0kSFkCccDcST0iDk1405F+6QXyatamt/y/FnM3XOVVsMBb/Hf7MyCYR71wW55MlsChiLzenORRlRtE/Vg+vMNZrA44huRRCJzkZu+/f1WYP1sKqVRi2T6bHYUdYpdQ08S8= 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=TN8PTnEo; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=VdO2Btbs; arc=none smtp.client-ip=103.168.172.152 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="TN8PTnEo"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="VdO2Btbs" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 82D821140157 for ; Fri, 26 Jul 2024 08:17:36 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Fri, 26 Jul 2024 08:17:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996256; x=1722082656; bh=ddAW6VeUYv WS2iD8O/EHi6WrPlI6zifUsy/DBLoc5Fg=; b=TN8PTnEooFnJFsgcYxZDbSuHfQ C6eLY5fVdU7kAeiWaUTdF9nOeZzZYi0TNDMQHCwa8S0+6x/HxXHpMxZ3FJXtxnlO YDcU3qZl+fc7KG9WlTXH0qAIpf0CuZj3v6ZB9y/Ti5hnmS3Ae+VI6lqJR0jXD7Ln VdUmgC/54evj3NPG/OMD51B0mDzDItV0NnLP/XoUm0K9ziGZOwoYaxpEeOvv2u3J sQsCGMxEAja5P9BAx6uUqaSfEL+7oQvXw0dI7dcYcjRqGihCYZEgtJ907PHvteGv TNEF5tjwbrs35emaz8dm5z9+8K2uQYacuEU/1JzzqwSOxQ6JlhOjpL6e5Lqw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996256; x=1722082656; bh=ddAW6VeUYvWS2iD8O/EHi6WrPlI6 zifUsy/DBLoc5Fg=; b=VdO2BtbsCs5t0uXffVNDv9W8CAIdlf+q5xgr8hW6gRhs hAn9w+MRx6+WeZ7q4gUett1M4LUKwhCg6t0XxwYapRzX+DN5SSh5GlsYsvDVPQWY 9ap7QkUD36YjGL9xGtyLDQAmyCDvp4ee2ZUFr80QhCJDkAaBY756FcgAdPR/fCgv bOSz2dJJgrC3sgoeoOQpU7agq1duIj6YFOgn/B8w85liaCuK9Nwegl9OQR6fWyig YNghw3tK6Om47RlxHjz3Pj4Du+/D8ijZYZrW8aqBysl1vINEAjrboZYiwSJ7m4G2 Whq3emKbKnrBvnYI3w5C0KeLk9vMokZuI/INzj+oLg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:17:35 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ce07156b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:16:15 +0000 (UTC) Date: Fri, 26 Jul 2024 14:17:29 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 16/23] builtin/shortlog: fix various trivial memory leaks Message-ID: <778e87221ac1d8cc581a8c3f3572810c68686451.1721995576.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 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 Fri Jul 26 12:17:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742740 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 55B57179652 for ; Fri, 26 Jul 2024 12:17:52 +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=1721996273; cv=none; b=KA9HAb7D3D2fdMpsS8T68P8TiNFwkDvch2XnMNODROber1BRVnTDsT/cjpS8Qwlhyjm38snhKy/y7n0bEYIY3RsgnZ57AAdzUVLc3r3p7KLLqqVreJNVpf7xKIaAgYlWBE5T1q0bcnkWGdy3zGI94oiTWHEYnFtyWTbW7CmA0Hw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996273; c=relaxed/simple; bh=AF9ZiNGG7vJNey1lFBa/JfRU7z8XNp18sHxdqYIV0pQ=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bLm8WaqBUx0qD18yGoSMUtq7kc2k7npiXtmesIMcs7c34cgtn7RU64ltn3h0ylTMV2B6PC60RyXqY34TaLX0Pf4J2IEF5oQ+EhHbNtfSak1eSmT05NY0hDnZmh3G6ZaUgIYxB6RENE7sJ4QDWWs+LFtu2cwlB5Qi9HCybiu8uH4= 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=VxuV+64O; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mLYOVjoq; 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="VxuV+64O"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mLYOVjoq" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id A3F0F1380602 for ; Fri, 26 Jul 2024 08:17:51 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 26 Jul 2024 08:17:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996271; x=1722082671; bh=nj3cpbyaCL PTXFxQ2U0P3OipQ02VdlkoMGA8clTMt0A=; b=VxuV+64OXl2f2MuG/x5pRArlb+ HvvYBkcpFGtIMLgXu+m5dxnC10G5r2p6VtrdG5ktDXtJnv7lkaIOhcS8oPGwHivF IXWZ/iNhjjnkWmcGyRbHk4d9MJYb82Q+Br4Xba3w2Z5jkiAbMy2Wd/mgQu+LSRj0 swDP0rT7hhS3TOC8VsBgugzDdkxrd4wnfjsOdAXT3uqjAHcVfbSSSL2OFvWMJ1cV bABqdifiM/KFTnio+UaD/ZgrlN0VNvxfOprngP1Mzq+RvFE2UYTOwmgvvwgRoPNL UgerIRzaUKZIdHQtXPZ9Ek0XU/qa4cVhu59XmZHKNj1VMIIMKDfkx/d9j90w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996271; x=1722082671; bh=nj3cpbyaCLPTXFxQ2U0P3OipQ02V dlkoMGA8clTMt0A=; b=mLYOVjoqhoWL8oOczJNZyNmDlDEkEm3uqqJUG8xAMfs5 148PZvLWh6kGnAlssn4qmd8SmJ4Rjrz6vQ+e4u92x8V7gSgITqxH3aXY6hQN3jSz 6xGfvUT9Rwb/MOvzaSQHI/csN5oKxzqc+9ak9m4bvJ/lID9UFRArRbzINBcmorrk PlZH8EIMx7w8ksopRhV7/TUzM385+mwOefGL4tYsz4B1fhXyxLyKfv1yD3DhHr/W 2XP1tFLkjhtoXkMPcQ9Ylkra0R+qUvbjU1r+lrpribsJP9D3tPze2jY8/ldjS5zi jytr5O+pmQ9U2JlE0P7LurFyFdtkSxOdyr2+W48reg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:17:50 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 4fe00da8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:16:28 +0000 (UTC) Date: Fri, 26 Jul 2024 14:17:40 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 17/23] builtin/worktree: fix leaking derived branch names Message-ID: <8a649bf7ed38297c9a2d3ec856368603e31adb7a.1721995576.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 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 Fri Jul 26 12:17: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: 13742741 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 94FEF178378 for ; Fri, 26 Jul 2024 12:18:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996294; cv=none; b=QTajkTT5tLz9ykqXJOxv7Xlw9xl8slfW7v+wRWHx7Q9NYa5nQEq6Vh8i/4FZLEU0tFc6aSjdTyo4sa+AKoc0wJWC4pAujMQ9Ci4TLDEBgy2Hsv986pyZqfWZhTWE1SdsJcIcOlFsJ6jJnjjyGTwTEYee7mw3vVNYuOHnzCY4cbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996294; c=relaxed/simple; bh=FGEooeWHeD4NOrWlUr0g6o3q+d/vNwxkkoAl1aT1wcs=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sxzRB5SNLnbdqFK7vzoOY5f2msYtjF7d/9th6tU3Xg5WZAvawCRtRaY0YMwMSv/P+5MOaU2O8VTp83RipDOCysoEWuy6pwEbQOGgecG1BhLh4/8dRV7WhAIKcyEnW7Cybn1+ryxgdngnsnNkWVRfmF9PvjzflCm9uVj2PL1cXmI= 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=EEDtMOvT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mOW/2oTh; arc=none smtp.client-ip=103.168.172.152 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="EEDtMOvT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mOW/2oTh" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7829C1140205 for ; Fri, 26 Jul 2024 08:18:11 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Fri, 26 Jul 2024 08:18:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996291; x=1722082691; bh=6G5HottkRB NwQgrTc9kobVD/9Cbq5r8DDIkmuMKDOJ0=; b=EEDtMOvTTl1bFqWyOs9KfS731Q lie7EZvLKWU5OOuOql/lMLRxpfxbcDMBWTHevD2sK5pOkB1oSKDbA249vjjy8BZF mmWL/uwataM4q7PGwqWKedtXqJsTagyns3UL1UGHwgFhH8C7tqbzgxk5zB0GLMnE 1okc/t7d20WXjk3LHLoLG8SoQiJi1JnscbVdpsG7od+/vSWTFKcPdVgYTsZ2y7wm C6kC8yGhQjJ2tqEBH3rRZgra7Nmm92zxQZKq9ybPCScI2SoVyL1pBLO/g6PB8QW0 0d6UMiddy/fqyT9esrUzgN2LvjR3tQvqU++1T03IQNQ6eSzYVADibKV9pycg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996291; x=1722082691; bh=6G5HottkRBNwQgrTc9kobVD/9Cbq 5r8DDIkmuMKDOJ0=; b=mOW/2oTh4fRS2UvMVHM8SuL7n90J577FM6IFZJwRusN5 X5aNGxV03JOpWKGmzJJ5e+D/V7rug7ROh4HSVEvjgR4D7kufo2d5hQaFxeHMSg8S 3hMGk9hoCogMBbZmn81sj/1+ljR44c9q3Xyo/5NkmjGZ9oaLgeNCLb5tXk6O0ZFQ LZSAMLPJ9VCtxx9m6enwKCJxJnk1RXjgBsjPo8b7dQ+J/UXvAo9HkCBFjGc8em2c DVgyu20a28Qf+sEMcKk9eqes5yz1vmz4PW31dmr+QUDFQ2yjAgCzLyq3sAbrnTiQ SxdCCq/muRo3Knf7GfnLZwEGStskOzwrGm9OdN0HcA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:18:10 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ca5611e2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:16:49 +0000 (UTC) Date: Fri, 26 Jul 2024 14:17:56 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 18/23] builtin/credential-cache: fix trivial leaks Message-ID: <2c7a3694903e54dcfa2eadb3b7fa7828da42f5d3.1721995576.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 Fri Jul 26 12:18:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742742 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 BE3FA178378 for ; Fri, 26 Jul 2024 12:18:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996311; cv=none; b=cXi6sox1xueZuws+eZZeO4V20Ad+VXOaseAsQxDN7q3m09sLXwlHxRIbY+f6KyS0y8r6lTiGSTr/8GhLvFvWOT8gqKghBRdVuv+je0UccSrZpMOE1FOjUPf08Tu6sfyJqfEjVDp+/Ne+ojQ6oVgpUKUu0abaXglbx1APUfwtiLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996311; c=relaxed/simple; bh=VSMVoLaOwb4c7TqovyHrWoMNA+yjYsrwsrq7jnbHqs4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LsYN97d74C2D9f7Tlk3vX+fmIwrDivf8ehWb8L1pr5kvjy5yZWnihbavkTFskpCAe4c6qgduAv0SY9ao6GyaryP8D0oLCTbkIiuB+Qkk0NxM9dXFaOzoeFAa3iFm4pRBSB/Zpd1GR3VaAWuGArHd9CXfCMzW0B0qib6Q3QYALQc= 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=hpJlDCdo; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=krfrDc01; arc=none smtp.client-ip=103.168.172.152 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="hpJlDCdo"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="krfrDc01" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3A8D91140205 for ; Fri, 26 Jul 2024 08:18:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 26 Jul 2024 08:18:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996307; x=1722082707; bh=+jvOCnjYNP IiMupll4cxgNbJsKoHW0mYAcAEiEZfWwU=; b=hpJlDCdojktQTEW5KNbKAWzOJT 7CZTXvkZBkIFZYNPXzJzJhWbjRhEQ8A41ioF/7Lc8/EMWI694NHA1PY6dbLCM/cF /kJPQH7sFsqJDabMrVCRQuI9UdajKDURMziSPZoIutjM4VSv0xhgZfKUYIjOkJ/5 o4pUK0gOZ+uUgUSRNbjWg7v8L5U3kYVx7goNOZqgeKkURO0JHcsc8SqgAqqKc93u +BqBA+8zKWcJPcXPBXbeUz9waGBuRvUZVXIUa6TrbqbcW3J5G50g/ydfc6EYlfwx xit1ZiuZzgt1o0pn+EuJ57ik/JSNIcqpb0PG+COH9kx6rHgC4sJZNAWov6Ag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996307; x=1722082707; bh=+jvOCnjYNPIiMupll4cxgNbJsKoH W0mYAcAEiEZfWwU=; b=krfrDc01fAe8ftcMsRuEYIik5Jj7g2Cmtp7PiNqqMjkN KVmzi6rjL0wvI7b3I1sejnBiEV0DS9Tr1rjj53YseihJwo6v+cWLFfA8DpeQPILR 0RLYu2Ca2F/4/xfGm3CDummzd8qA+KjwR8q2N8guYRQndKh/svMwItwp00Zh+8pl VxcqM/Nh/vRZDfB+Ls8lflIwYuP4Ga6IKWWLGBoXmoWolGyQjI6Odtnk01WmRdX9 MEOF3WYczyyt/ZN7K0UH5ALNz0uEfm36pITYbRurcAaB8GL86tM5MU9CGuJ0L3b3 OrblenUbKqY2H/JWaEibxVEFP7y9ZM/F5oYkyjEvaw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:18:26 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 6e0b7603 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:17:04 +0000 (UTC) Date: Fri, 26 Jul 2024 14:18:14 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 19/23] t/test-repository: fix leaking repository Message-ID: <7564911d2ad5332ea1f70b51868585819e895b06.1721995576.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 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 Fri Jul 26 12:18:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742743 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 4C9A517B424 for ; Fri, 26 Jul 2024 12:18:35 +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=1721996316; cv=none; b=l9qYje5h3VhcRRdnamufSEDbXILDU6Rf9iUF9juigi4gcWW/VBG/AYhLzttqTQnhWXr9oVr70hMt2RpwAacGbvlljj89JkgPgBTcL07s4WV3EKOX67TtIdC/Ld6bNupcdZ031aKmLNhl4ZXDqCpvb65hQdV3apBO2P5+v4CLK4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996316; c=relaxed/simple; bh=Gx8tvAXvFncz9+cp9P9DSw79WyMamNxqcpyHmL49eg4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=d5xLNwXZ5hPdxoyXkD0LXAzK4bx92LgpKWWwIsTYp3X7FKIQprBC3xE6VdZnXv0ot2B/F9rUr3nZOhKG6fWDW1jE9NtG4v6tsIVhilsIz0QkL5cINrRDJBARbL78bc2Y+n8eRQ2elIEOMY3Ivc5Pcza1H0VYsI8PTLm4bU3QJlw= 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=kbXtVVzB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lwoGAaA/; 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="kbXtVVzB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lwoGAaA/" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 6C8C213805F4 for ; Fri, 26 Jul 2024 08:18:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 26 Jul 2024 08:18:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996314; x=1722082714; bh=wL+D0RVhQn yuTIhNTHmcvNKnOTeVtyC5PuFO7AVRZTk=; b=kbXtVVzBAvv0pJfmabkWiktk+f coBhUvs+vLpCZXdDh5zfWtFW3EdouVRMWhL2MfxFQNtctaccvjIojuKvRk3K5HlK mDdMOz2kt05SHQ/cbwVcatW/djM6TJybMLTbmoc6vaJohXBsUwjczFqPGfu//VRQ nHuIE2qKo9lmejQ9ODbkJSwgkim3pzB6CgH6zq+h0LJpKbqWPX0Mnh9os+28uHoY xvS6WHE5gLN/gTikSF9TiJNmt9rGNdaYwBedlxPE87lSt+sKxvwRenThS438Ot5D 4N+/zmrAZJ7iicQ9y/IKxL/3zuBSipAkPXriQH/SXITYO8NF1N8D3P+n7uXA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996314; x=1722082714; bh=wL+D0RVhQnyuTIhNTHmcvNKnOTeV tyC5PuFO7AVRZTk=; b=lwoGAaA/4CiCBxlM/8tmAOPj1lLzHWsK+6z0zwyF4AiN 64LRz+YuGyBW9w2DzLMNdiIpG9gtr/MAqdWzBfxFkt4k4K4AMshELRYJAQeHJn43 nRmel26laGDaqd+pwgf+I0TIXUoJ3ocNA11ZbDmJMu5wp5S/qa3ghCHE+ghCjrSC oz3gjRu7j5lGXSvoVwtoxJUrRYHWiKnJhqWuzkJ8Do39D7J5KDFmgD2nLhvwMpbI uV1Bd3WPFbcc1QZ+Ip6JEt9hmUq7Nqn6zbdNn0UpRNoeModI+z4flG2t1g9aVgD5 fEr6dpX7Mn5NcI9GGBdXI9SWklBAs5W6KymjCKihMA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:18:33 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ec540b50 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:17:14 +0000 (UTC) Date: Fri, 26 Jul 2024 14:18:28 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 20/23] 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 Fri Jul 26 12:18:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742744 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 3E697E57E for ; Fri, 26 Jul 2024 12:19: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=1721996352; cv=none; b=hvz6GsEUIxueqjRKOwJuSNUDvvIrcVkxKRfyVdPaBewmbLU925NyQqO9Efmlvmv1FxXEApr6jVbU5/yzHpMmRq9n6HdxEKrvF5mBZg8h11zaoiDpaAJ+qd/+CZDrbDdq1tDgvUTdWwqox6rtuE19jZc4J+OfireKs9L52zlHDU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996352; c=relaxed/simple; bh=rmpiy5hwE4FV64d8alnUwdZLadBiln3/H1UwsdLc6Es=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=n9ICUVdDthnbo8zzWJrBDvlW3qekGTbNup6oqUqtLjy5HR8yzyskiJXY34EmPlP0GHebwX9gcSvYGw6yD+8PF+0mX6VVYlZ82tMqL/g4QF4nMCvFK/8/aZNz8JeULbssF+6hH4YhlSaFTZcZ39fz9nTovomogS8KqBVUrDWXoAg= 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=gq50Wn2W; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=VJJ1e5OO; 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="gq50Wn2W"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="VJJ1e5OO" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 5BA4313800B5 for ; Fri, 26 Jul 2024 08:19:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 26 Jul 2024 08:19:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996350; x=1722082750; bh=oenikin661 0tWh48CMlXxSfi3YtE5E1SlEkRwQxdGyw=; b=gq50Wn2W74D2L1LzlaYYgsGCrh lH9v13ghbXHzvLfGYhjkwki4Zo8Knn6t6zcS4PdlZteEr5Kfa1HvZnRFzoZW0W+U KWBPBgLpp9ZIIjFzzfvsm/rkruOaHrYQ45XyLyzXEfss+CLVNow6d4REDIYownCr VcDGtvZu3pOFzhHh2P7RPtmH7CqU13w/drkDVtlN5p/hwB7PleCt5gadIO9mkhji mxQJC3RDBsPVqMFY3y3MMmnJElBw3i/O9b0lDKiJUA3dDlPfbjfEct1v1TOvYiYp JyyA+NOJcpI0Zan5WgLTVhE4KAsjjGjSYQZWcJFm0JSZl3XlXbkGAl3W5Vdg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996350; x=1722082750; bh=oenikin6610tWh48CMlXxSfi3YtE 5E1SlEkRwQxdGyw=; b=VJJ1e5OOFw9vN2oE8a8fyzbpOmJXh8hhaSaYJIOy/+LH mUh/hG0xP3iZo9OmQOMuV6cdkvhsgI09NodeDYgf95yhuYRCR6saaam2QQyKOeEF qEvCpLpECMSIHyQa9fMi6RXvbEUxJDvLyZ7w0A8LCRf4pJVPUZCTv7p8+nCoN0EY lof6KfNdLcaSYsEJQ6qaLNBnYih62Y+sbTIN/R1MTrvdVUi8uiSEMqE7a9WCziaL MthOLGk4g6vDtpFe9zdUI9GeKKfZDZx+QG59tyczWDGG4YhRYe65vhpHQoAhVydO kztfLKTzwA95Rr3zMme2W3HhAMKSTJNEFOjQmAV8Zw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:19:09 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 3c606302 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:17:49 +0000 (UTC) Date: Fri, 26 Jul 2024 14:18:53 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 21/23] entry: fix leaking pathnames during delayed checkout 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 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 Fri Jul 26 12:19: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: 13742745 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 43501E57E for ; Fri, 26 Jul 2024 12:19:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996361; cv=none; b=VwyBiE6StCcQlndIuQ1CMnKuh607xXet3ZKrIkUQx2rwyIltDSGrxJeM8PO/0XxtZ0uxtCu6O5h+GqU6AslOjWPXCF51K5zxR6is+Nnv3qWXFHi/JPg58W7mNZ4FLGLN89D3i2nqsQZO4XGUKFKj5SZCmMi0Uk9pBH/COGd7TpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996361; c=relaxed/simple; bh=ZIY1ixpdXYcyLw4oWIUVCMnZLL53ib7mQXksKLHk+7A=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bOVSbDsEo5Y2Sz1SLFa7qTDyugMGllgXbitOPRR1fS2jhsqGH8yde6HTEAzpS21ohO++muNitTjheByPHAK9VfPe+cjkBe8qXB7eKZf8ay9ipCYESDEOUxNKvXIuk1GrllH6mC9WE/AzQ13Gc4Txl+GY0FQby0PfOPyqdg/XoAc= 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=hkxtizUu; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TRgX2fKw; arc=none smtp.client-ip=103.168.172.152 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="hkxtizUu"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TRgX2fKw" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 4797A114011C for ; Fri, 26 Jul 2024 08:19:19 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 26 Jul 2024 08:19:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996359; x=1722082759; bh=1WlWpc5COf SBO47vkPA6pJKIC5F0q7xhRRb/A7Dcouo=; b=hkxtizUuEd6RH9MPosSJ3NX8ki iByfJe5L7bQea6EPHnsItYF4pvxjQVfEr4AkE6hS4rgqXi5oMmEWMkLY1HySQekG 5wUeHLBAqfy941/r+iPWe2G25MbPXEug01RMr2ou8u9GE6e2vpWwCKdC0vLz0/5+ bcPcsirh1ZMYEQZnLv+DoW/y+u+NuvbqGr9acaf3lByqtuqJmbjIKyIBJ4X569Sk d7fkUe5XTOcTVvyfTQignMWcZpBw8rSAFOrScR/LZ26nJMyVrtifM+cAx0jy1wrk rJ2c/2YAYN4k5yszDjiaU3hPHHZ8cHg4k8lGCsr2MWXO9gENG9f6q+sX+JQg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996359; x=1722082759; bh=1WlWpc5COfSBO47vkPA6pJKIC5F0 q7xhRRb/A7Dcouo=; b=TRgX2fKwGYfTqt6brBMko3RNqJO2flRmTSi8ipSwjjp0 QvMKCd6heRe/BUTPcZOzN/t2Br2YIWQcieQNynfg8IRAvLkpnDrlRYuREZ4O/Li0 tgFFAiPW4nYk0Z+KwCb8TZH60GoQ+E5yRQgZ5NBS+InxxNFG+6FFm9iCx/DWopHJ dOwomN2hbSZI9xyjBjQBWlUyLYRywBYs1YLQccu8VGYhCOdiRbS2D/Dy1mpfOPcD tS1Cr4CuN/0Ox3Lc4h/8nRlkKQ2Y+ItvKA8nQr44RCxOv+W+A3wN4YyPLE6sOuaK YxT4iTfMGfN02IB0WfldcC9+L7Ihw4u2xmPQfKSsyg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:19:18 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 70fd3aa0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:17:58 +0000 (UTC) Date: Fri, 26 Jul 2024 14:19:12 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 22/23] convert: fix leaking config strings Message-ID: <8c2a19994fcda53cc1cb315c8ab87a36838d598b.1721995576.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 Fri Jul 26 12:19:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13742746 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 D3EFAE57E for ; Fri, 26 Jul 2024 12:19:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996375; cv=none; b=IKIA339hOvS3dZ8qlZ2JjJm/p64IlE3UF94JU6cbICOS2+SdO+HZz8YiJgeF4rM611HuKCnN09T0eqddzi83orWUK1E7gicf6EkneEz4lXnUGMpJhoChY7bFVPxRLU/N98tamajK6BwpxdLgfvqDjljvhr10WSJD5qbJHV1W+u0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721996375; c=relaxed/simple; bh=SLWgMdu0Xw6GNQwQ9l8xZr9EO8TIWCQOsQ1weYPE384=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cNU68rK0daZu965xevARA3oI7t8IfAELFuUSa1istok+Fi+hnLPwg0N3Knti9OHiPiB2MbeIMhhEILDYSg1ZrERbFusabPKAk9vZdgryzJhlWXv26pYRKi20kCd7fAVU6srYIjkk0vyi7APFy7Nq9Ex4N7P3KlsiIn/xi1EVhz0= 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=XxoKkgYm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=tJHwFigd; arc=none smtp.client-ip=103.168.172.152 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="XxoKkgYm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="tJHwFigd" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 65079114020E for ; Fri, 26 Jul 2024 08:19:32 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 26 Jul 2024 08:19:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1721996372; x=1722082772; bh=Qk3A039ivy zhONKQghmlPyCFKQHuELNJHfjZWLcVy5s=; b=XxoKkgYmk6ysExX+xFCNJEGST6 F8BMpin47P4IzSgZLtoFS0tl4g27n/IY0Z7Gw9sC9eMCMjivWZnhv1ktSVf2RwjR eoes0DCix35d0eOd8mBcXlrqjnAsFKRUv/fa/cpLrwPscic8QAXrtvF4GZUHLubR CQ4PwREYlArErP8J/A7sv1RywxIW6x6Z6+CVhhFlbbiki7K6CEgaHhz4o5snftqV 7+jLxzlRYK4l0DmKOgdC1ACHEF+wNnPbpQDoK6aCH+rDmsmRlKjxiZVk8A1gPGFh HFKk7rXP5pjQhSFEIb0YE6TNB5zN0px/5wIfHf5hObZfoD68CPJ5VTw85OJw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721996372; x=1722082772; bh=Qk3A039ivyzhONKQghmlPyCFKQHu ELNJHfjZWLcVy5s=; b=tJHwFigdNrPHL4HZPjRUCHqGCtogtbcOzfcOL920n4gH 0dPTYIz93xwhz7S+PVlcS2pXl/Fv9LIz0iI4Qgpfu3wx6snuKXEtlKJF7DRSzN7i hCLeCBK5ImEkPoXBvr0Bmeq8/LgijPJpojL62vjLNPFWf+t2icHTYN2pfoJHY0rR 1KsDVmYkhBfbTP/SOT/7TwSGpx9xE6qPHwOSvo8L9BZKP7MahQyfgc1aFyb5qMSU 5tnJnAgpHBY3j59+Fl+jhzInfjYBbydVJ/NWQI5RzoSlzqrUyoyVWGCqsBiB69uu ckoqgDzhsptdTKSLQfZ9IROizHkqJzpLmNAb7w5IKA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrieehgdehvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 26 Jul 2024 08:19:31 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 9516ce33 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 26 Jul 2024 12:18:11 +0000 (UTC) Date: Fri, 26 Jul 2024 14:19:22 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 23/23] commit-reach: fix trivial memory leak when computing reachability Message-ID: <60aef16aef5e5733d449b3e9fd1a8816b5d82c27.1721995576.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 '