diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-11-20 14:39:45 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-11-21 00:23:44 +0100 |
commit | 7720dbe99b303b3d658898587e02d7cf224a93c3 (patch) | |
tree | 7ea30898b27757fb7469050f7052de489ec7c2b9 /help.h | |
parent | help: fix leaking `struct cmdnames` (diff) | |
download | git-7720dbe99b303b3d658898587e02d7cf224a93c3.tar.xz git-7720dbe99b303b3d658898587e02d7cf224a93c3.zip |
help: fix leaking return value from `help_unknown_cmd()`
While `help_unknown_cmd()` would usually die on an unknown command, it
instead returns an autocorrected command when "help.autocorrect" is set.
But while the function is declared to return a string constant, it
actually returns an allocated string in that case. Callers thus aren't
aware that they have to free the string, leading to a memory leak.
Fix the function return type to be non-constant and free the returned
value at its only callsite.
Note that we cannot simply take ownership of `main_cmds.names[0]->name`
and then eventually free it. This is because the `struct cmdname` is
using a flex array to allocate the name, so the name pointer points into
the middle of the structure and thus cannot be freed.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'help.h')
-rw-r--r-- | help.h | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -32,7 +32,7 @@ void list_all_other_cmds(struct string_list *list); void list_cmds_by_category(struct string_list *list, const char *category); void list_cmds_by_config(struct string_list *list); -const char *help_unknown_cmd(const char *cmd); +char *help_unknown_cmd(const char *cmd); void load_command_list(const char *prefix, struct cmdnames *main_cmds, struct cmdnames *other_cmds); |