]> git.ipfire.org Git - thirdparty/git.git/commit
revision: free diff options
authorPatrick Steinhardt <ps@pks.im>
Tue, 11 Jun 2024 09:20:24 +0000 (11:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Jun 2024 20:15:06 +0000 (13:15 -0700)
commita90a08961190dda2f664e102822fb6a7152e65d5
treeb6f03e1e209ce13e1d8d0750de35e7d0181807cd
parenta282dbeba718db156678aadec6c47ba1d9f13d0f
revision: free diff options

There is a todo comment in `release_revisions()` that mentions that we
need to free the diff options, which was added via 54c8a7c379 (revisions
API: add a TODO for diff_free(&revs->diffopt), 2022-04-14). Releasing
the diff options wasn't quite feasible at that time because some call
sites rely on its contents to remain even after the revisions have been
released.

In fact, there really only are a couple of callsites that misbehave
here:

  - `cmd_shortlog()` releases the revisions, but continues to access its
    file pointer.

  - `do_diff_cache()` creates a shallow copy of `struct diff_options`,
    but does not set the `no_free` member. Consequently, we end up
    releasing resources of the caller-provided diff options.

  - `diff_free()` and friends do not play nice when being called
    multiple times as they don't unset data structures that they have
    just released.

Fix all of those cases and enable the call to `diff_free()`, which plugs
a bunch of memory leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/shortlog.c
diff-lib.c
diff.c
revision.c
t/t4208-log-magic-pathspec.sh
t/t6000-rev-list-misc.sh
t/t6001-rev-list-graft.sh
t/t6013-rev-list-reverse-parents.sh
t/t6017-rev-list-stdin.sh
t/t9500-gitweb-standalone-no-errors.sh
t/t9502-gitweb-standalone-parse-output.sh