git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/1] diff: munmap() file contents before running external diff

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Jul 11, 2019, 08:23 UTC
Message-ID
<8a0213291b2afc8db9243808319dc86b736122c8.1562833419.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.213.v2.git.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

When running an external diff from, say, a diff tool, it is safe to assume that we want to write the files in question. On Windows, that means that there cannot be any other process holding an open handle to said files, or even just a mapped region.

So let's make sure that `git diff` itself is not holding any open handle to the files in question.

In fact, we will just release the file pair right away, as the external diff uses the files we just wrote, so we do not need to hold the file contents in memory anymore.

This fixes https://github.com/git-for-windows/git/issues/1315
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 diff.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/diff.c b/diff.c
index 4d3cf83a27..42affb6dcf 100644
--- a/diff.c
+++ b/diff.c
@@ -4206,6 +4206,8 @@ static void run_external_diff(const char *pgm,
 	argv_array_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter);
 	argv_array_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr);
 
+	diff_free_filespec_data(one);
+	diff_free_filespec_data(two);
 	if (run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env.argv))
 		die(_("external diff died, stopping at %s"), name);
 
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Junio C Hamano
Message 7 of 8 in “diff: release all handles before running external diff”
  1. 0/1 diff: release all handles before running external diffJohannes Schindelin via GitGitGadget, Jul 4, 2019
  2. 1/1 diff: munmap() file contents before running external diffJohannes Schindelin via GitGitGadget, Jul 4, 2019
  3. Junio C HamanoJul 8, 2019
  4. Johannes SchindelinJul 10, 2019
  5. Junio C HamanoJul 8, 2019
  6. 0/1 diff: release all handles before running external diffJohannes Schindelin via GitGitGadget, Jul 11, 2019
  7. 1/1 diff: munmap() file contents before running external diffJohannes Schindelin via GitGitGadget, Jul 11, 2019
  8. Junio C HamanoJul 11, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.