Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git log --graph -u hangs #5193

Merged
merged 3 commits into from
Oct 7, 2024

Conversation

dscho
Copy link
Member

@dscho dscho commented Oct 7, 2024

This fixes #5185 by backporting gitgitgadget#1806 (which, sadly, seems not to have made it into Git v2.47.0).

derrickstolee and others added 3 commits October 2, 2024 22:07
The output_prefix() method in line-log.c may call a function pointer via
the diff_options struct. This function pointer returns a strbuf struct
and then its buffer is passed back. However, that implies that the
consumer is responsible to free the string. This is especially true
because the default behavior is to duplicate the empty string.

The existing functions used in the output_prefix pointer include:

 1. idiff_prefix_cb() in diff-lib.c. This returns the data pointer, so
    the value exists across multiple calls.

 2. diff_output_prefix_callback() in graph.c. This uses a static strbuf
    struct, so it reuses buffers across calls. These should not be
    freed.

 3. output_prefix_cb() in range-diff.c. This is similar to the
    diff-lib.c case.

In each case, we should not be freeing this buffer. We can convert the
output_prefix() function to return a const char pointer and stop freeing
the result.

This choice is essentially the opposite of what was done in 394affd
(line-log: always allocate the output prefix, 2024-06-07).

This was discovered via 'valgrind' while investigating a public report
of a bug in 'git log --graph -L' [1].

[1] git-for-windows#5185

This issue would have been caught by the new test, when Git is compiled
with ASan to catch these double frees.

Co-authored-by: Jeff King <[email protected]>
Signed-off-by: Jeff King <[email protected]>
Signed-off-by: Derrick Stolee <[email protected]>
Now that output_prefix() returns a const char * type, it matches the
behavior of diff_line_prefix() and no longer needs to exist on its own.

Signed-off-by: Jeff King <[email protected]>
Signed-off-by: Derrick Stolee <[email protected]>
The uses of the output_prefix function pointer in the diff_options
struct is currently difficult to work with by returning a pointer to a
strbuf. There is only one use that cares about the length of the string,
which appears to be the only justification of the return type.

We already noticed confusing memory issues around this return type, so
use a const char * return type to make it clear that the caller does not
own this string buffer.

Signed-off-by: Jeff King <[email protected]>
Signed-off-by: Derrick Stolee <[email protected]>
@dscho dscho requested a review from derrickstolee October 7, 2024 15:41
@dscho dscho self-assigned this Oct 7, 2024
@dscho dscho added this to the Next release milestone Oct 7, 2024
@dscho dscho merged commit 46171c9 into git-for-windows:main Oct 7, 2024
45 checks passed
dscho added a commit to dscho/git that referenced this pull request Oct 8, 2024
This fixes git-for-windows#5185 by
backporting gitgitgadget#1806 (which, sadly,
seems not to have made it into Git v2.47.0).
git-for-windows-ci pushed a commit that referenced this pull request Oct 8, 2024
This fixes #5185 by
backporting gitgitgadget#1806 (which, sadly,
seems not to have made it into Git v2.47.0).
dscho added a commit that referenced this pull request Oct 8, 2024
This fixes #5185 by
backporting gitgitgadget#1806 (which, sadly,
seems not to have made it into Git v2.47.0).
git-for-windows-ci pushed a commit that referenced this pull request Oct 9, 2024
This fixes #5185 by
backporting gitgitgadget#1806 (which, sadly,
seems not to have made it into Git v2.47.0).
git-for-windows-ci pushed a commit that referenced this pull request Oct 9, 2024
This fixes #5185 by
backporting gitgitgadget#1806 (which, sadly,
seems not to have made it into Git v2.47.0).
dscho added a commit that referenced this pull request Oct 9, 2024
This fixes #5185 by
backporting gitgitgadget#1806 (which, sadly,
seems not to have made it into Git v2.47.0).
dscho added a commit that referenced this pull request Oct 11, 2024
This fixes #5185 by
backporting gitgitgadget#1806 (which, sadly,
seems not to have made it into Git v2.47.0).
dscho added a commit that referenced this pull request Nov 22, 2024
This fixes #5185 by
backporting gitgitgadget#1806 (which, sadly,
seems not to have made it into Git v2.47.0).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Git log --graph -u hangs on version 2.46.2
3 participants