]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/help: fix leaks in `check_git_cmd()`
authorPatrick Steinhardt <ps@pks.im>
Wed, 20 Nov 2024 13:39:46 +0000 (14:39 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Nov 2024 23:23:44 +0000 (08:23 +0900)
commit2379b5c90038b2c334ff62cce62d50b4a8e78360
tree2941ab99c83742c28541861e5b5cb970ff9595d4
parent7720dbe99b303b3d658898587e02d7cf224a93c3
builtin/help: fix leaks in `check_git_cmd()`

The `check_git_cmd()` function is declared to return a string constant.
And while it sometimes does return a constant, it may also return an
allocated string in two cases:

  - When handling aliases. This case is already marked with `UNLEAK()`
    to work around the leak.

  - When handling unknown commands in case "help.autocorrect" is
    enabled. This one is not marked with `UNLEAK()`.

The function only has a single caller, so let's fix its return type to
be non-constant, consistently return an allocated string and free it at
its callsite to plug the leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/help.c