diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-09-17 12:08:08 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-09-17 22:53:30 +0200 |
commit | 3fc4eab466a3758ff57d8c823f244e29550a48d2 (patch) | |
tree | bd3807acab2037c9943c9c06773131bc34cb78eb /t/t4138-apply-ws-expansion.sh | |
parent | apply: rename members that track line count and allocation length (diff) | |
download | git-3fc4eab466a3758ff57d8c823f244e29550a48d2.tar.xz git-3fc4eab466a3758ff57d8c823f244e29550a48d2.zip |
apply: refactor `struct image` to use a `struct strbuf`
The `struct image` uses a character array to track the pre- or postimage
of a patch operation. This has multiple downsides:
- It is somewhat hard to track memory ownership. In fact, we have
several memory leaks in git-apply(1) because we do not (and cannot
easily) free the buffer in all situations.
- We have to reinvent the wheel and manually implement a lot of
functionality that would already be provided by `struct strbuf`.
- We have to carefully track whether `update_pre_post_images()` can do
an in-place update of the postimage or whether it has to allocate a
new buffer for it.
This is all rather cumbersome, and especially `update_pre_post_images()`
is really hard to understand as a consequence even though what it is
doing is rather trivial.
Refactor the code to use a `struct strbuf` instead, addressing all of
the above. Like this we can easily perform in-place updates in all
situations, the logic to perform those updates becomes way simpler and
the lifetime of the buffer becomes a ton easier to track.
This refactoring also plugs some leaking buffers as a side effect.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rwxr-xr-x | t/t4138-apply-ws-expansion.sh | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh index 8bbf8260fa..7981931b4e 100755 --- a/t/t4138-apply-ws-expansion.sh +++ b/t/t4138-apply-ws-expansion.sh @@ -5,6 +5,7 @@ test_description='git apply test patches with whitespace expansion.' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' |