Git Mailing List Archive mirror
 help / color / mirror / Atom feed
From: "Rubén Justo" <rjusto@gmail.com>
To: Git List <git@vger.kernel.org>
Subject: [PATCH v2 4/4] add: plug a leak on interactive_add
Date: Tue, 23 Apr 2024 00:54:18 +0200	[thread overview]
Message-ID: <f20291e7-fc2b-4ce4-a471-84cf76988f6e@gmail.com> (raw)
In-Reply-To: <69f86760-96ff-4c62-9649-4627652b7c19@gmail.com>

Plug a leak we have since 5a76aff1a6 (add: convert to use
parse_pathspec, 2013-07-14).

This leak can be triggered with:
    $ git add -p anything

Fixing this leak allows us to mark as leak-free the following tests:

    + t3701-add-interactive.sh
    + t7514-commit-patch.sh

Mark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix
promply any new leak that may be introduced and triggered by them in the
future.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
---
 builtin/add.c              | 9 ++++++---
 t/t3701-add-interactive.sh | 1 +
 t/t7514-commit-patch.sh    | 2 ++
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/builtin/add.c b/builtin/add.c
index ae723bc85e..b7d3ff1e28 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -150,7 +150,7 @@ static int refresh(int verbose, const struct pathspec *pathspec)
 int interactive_add(const char **argv, const char *prefix, int patch)
 {
 	struct pathspec pathspec;
-	int unused;
+	int unused, ret;
 
 	if (!git_config_get_bool("add.interactive.usebuiltin", &unused))
 		warning(_("the add.interactive.useBuiltin setting has been removed!\n"
@@ -163,9 +163,12 @@ int interactive_add(const char **argv, const char *prefix, int patch)
 		       prefix, argv);
 
 	if (patch)
-		return !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec);
+		ret = !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec);
 	else
-		return !!run_add_i(the_repository, &pathspec);
+		ret = !!run_add_i(the_repository, &pathspec);
+
+	clear_pathspec(&pathspec);
+	return ret;
 }
 
 static int edit_patch(int argc, const char **argv, const char *prefix)
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index bc55255b0a..04d8333373 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -4,6 +4,7 @@ test_description='add -i basic tests'
 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
 
diff --git a/t/t7514-commit-patch.sh b/t/t7514-commit-patch.sh
index b4de10a5dd..03ba0c0e73 100755
--- a/t/t7514-commit-patch.sh
+++ b/t/t7514-commit-patch.sh
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='hunk edit with "commit -p -m"'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup (initial)' '
-- 
2.45.0.rc0.4.gfff7e48949

  parent reply	other threads:[~2024-04-22 22:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-21 10:22 [PATCH 0/4] mark t3701-add-interactive.sh as leak-free Rubén Justo
2024-04-21 10:27 ` [PATCH 2/4] add-interactive: plug a leak in get_untracked_files Rubén Justo
2024-04-22 15:50   ` Junio C Hamano
2024-04-21 10:28 ` [PATCH 1/4] apply: plug a leak in apply_data Rubén Justo
2024-04-22 15:41   ` Phillip Wood
2024-04-22 22:04     ` Rubén Justo
2024-04-22 22:27       ` Junio C Hamano
2024-04-21 10:28 ` [PATCH 3/4] add-patch: plug a leak handling the '/' command Rubén Justo
2024-04-21 10:29 ` [PATCH 4/4] add: plug a leak on interactive_add Rubén Justo
2024-04-22 15:43   ` Phillip Wood
2024-04-22 23:04     ` Rubén Justo
2024-04-22  6:06 ` [PATCH 0/4] mark t3701-add-interactive.sh as leak-free Patrick Steinhardt
2024-04-22 15:30 ` Junio C Hamano
2024-04-22 22:51 ` [PATCH v2 " Rubén Justo
2024-04-22 22:54   ` [PATCH v2 1/4] apply: plug a leak in apply_data Rubén Justo
2024-04-22 22:54   ` [PATCH v2 2/4] add-interactive: plug a leak in get_untracked_files Rubén Justo
2024-04-22 22:54   ` [PATCH v2 3/4] add-patch: plug a leak handling the '/' command Rubén Justo
2024-04-22 22:54   ` Rubén Justo [this message]
2024-04-22 23:26   ` [PATCH v2 0/4] mark t3701-add-interactive.sh as leak-free Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f20291e7-fc2b-4ce4-a471-84cf76988f6e@gmail.com \
    --to=rjusto@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).