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

[PATCH] log -L: do not free parents lists we might need again

From
Thomas Rast <trast@student.ethz.ch>
Date
Sep 11, 2010, 21:10 UTC
Message-ID
<92a37c8a8d7157aa8bf4d654f4e5bd713c69382d.1284239099.git.trast@student.ethz.ch>
In-Reply-To
<20100830171007.GC21441@burratino>

The parent rewriting code of 'git log -L' was too aggressive in freeing memory: assign_range_to_parent() will free the commit->parents field when it sees that a parent cannot pass off any blame (is a root commit in rewritten history).

Its caller assign_parents_range() however will, upon finding the first parent that takes *full* blame for all ranges, rewind and reinstate all previous parents' line ranges and parent lists. This resurrects pointers to ranges that were freed in assign_range_to_parent() under some circumstances.

Furthermore, we must not empty the parent lists either: the same rewind/reinstate code relies on them.

Do both only if the commit was an ordinary (not merge or root) commit, in which case the merge code-path discussed here is never taken.

Reported-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
[sorry for the double post, forgot to cc the list]
After staring at it for some time, I think this is the problem.

Sadly I cannot come up with an independent test that reproduces it (or at least generates a valgrind warning). Based on my analysis I tried

 diff --git a/t/t4302-log-line-merge-history.sh b/t/t4302-log-line-merge-history.sh
 index 8634116..7c86903 100755
 --- a/t/t4302-log-line-merge-history.sh
 +++ b/t/t4302-log-line-merge-history.sh
 @@ -171,4 +171,17 @@ test_expect_success 'validate the graph output.' '
  	test_cmp current-graph expected-graph
  '
  
 +test_expect_success 'set up trivial side merge' '
 +	git checkout -b trivial-side &&
 +	echo new_line >> path0 &&
 +	git add path0 &&
 +	git commit -m new_line &&
 +	git checkout master &&
 +	git merge --no-ff trivial-side
 +'
 +
 +test_expect_success 'log -L on the trivial-merged file' '
 +	git log -L /new_line/,+1 path0
 +'
 +
  test_done

but that does not fail. I am hesitant to add your original test because it strays into the directory where git was built, to test with git's own history. It just feels wrong.

 line.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/line.c b/line.c
index 63dd19a..b0deafb 100644
--- a/line.c
+++ b/line.c
@@ -961,8 +961,10 @@ static int assign_range_to_parent(struct rev_info *rev, struct commit *c,
 		 * If there is no new ranges assigned to the parent,
 		 * we should mark it as a 'root' commit.
 		 */
-		free(c->parents);
-		c->parents = NULL;
+		if (c->parents && !c->parents->next) {
+			free(c->parents);
+			c->parents = NULL;
+		}
 	}
 
 	/* and the ranges of current commit c is updated */
-- 
1.7.3.rc1.333.gf62981
Previous: Bo YangNext: Bo Yang
Message 17 of 28 in “Reroll a version 5 of this series”
  1. 00/17 Reroll a version 5 of this seriesBo Yang, Aug 11, 2010
  2. 01/17 parse-options: enhance STOP_AT_NON_OPTIONBo Yang, Aug 11, 2010
  3. 02/17 parse-options: add two helper functionsBo Yang, Aug 11, 2010
  4. 03/17 Add the basic data structure for line level historyBo Yang, Aug 11, 2010
  5. 04/17 Refactor parse_locBo Yang, Aug 11, 2010
  6. 05/17 Parse the -L optionsBo Yang, Aug 11, 2010
  7. 06/17 Export three functions from diff.cBo Yang, Aug 11, 2010
  8. 07/17 Add range clone functionsBo Yang, Aug 11, 2010
  9. 08/17 map/take range to the parent of commitsBo Yang, Aug 11, 2010
  10. 09/17 Print the line logBo Yang, Aug 11, 2010
  11. 10/17 Hook line history into cmd_log, ensuring a topo-ordered walkBo Yang, Aug 11, 2010
  12. 11/17 Make rewrite_parents public to other part of gitBo Yang, Aug 11, 2010
  13. 12/17 Make graph_next_line external to other part of gitBo Yang, Aug 11, 2010
  14. 13/17 Add parent rewriting to line history browserBo Yang, Aug 11, 2010
  15. log -L crash (Re: [PATCH V5 13/17] Add parent rewriting to line history browser)Jonathan Nieder, Aug 30, 2010
  16. Bo YangSep 1, 2010
  17. log -L: do not free parents lists we might need againThomas Rast, Sep 11, 2010
  18. 14/17 Add --graph prefix before line history outputBo Yang, Aug 11, 2010
  19. 15/17 Add --full-line-diff optionBo Yang, Aug 11, 2010
  20. 16/17 Add tests for line history browserBo Yang, Aug 11, 2010
  21. Ævar Arnfjörð BjarmasonAug 12, 2010
  22. Bo YangAug 12, 2010
  23. Ævar Arnfjörð BjarmasonAug 12, 2010
  24. Junio C HamanoAug 12, 2010
  25. Junio C HamanoAug 12, 2010
  26. 17/17 Document line history browserBo Yang, Aug 11, 2010
  27. david@lang.hmAug 12, 2010
  28. Junio C HamanoAug 12, 2010

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.