built-ins: use free() not UNLEAK() if trivial, rm dead code
For a lot of uses of UNLEAK() it would be quite tricky to release the memory involved, or we're missing the relevant *_(release|clear)() functions. But in these cases we have them already, and can just invoke them on the variable(s) involved, instead of UNLEAK(). For "builtin/worktree.c" the UNLEAK() was also added in [1], but the struct member it's unleaking was removed in [2]. The only non-"int" member of that structure is "const char *keep_locked", which comes to us via "argv" or a string literal[3]. We have good visibility via the compiler and tooling (e.g. SANITIZE=address) on bad free()-ing, but none on UNLEAK() we don't need anymore. So let's prefer releasing the memory when it's easy. For "bugreport", "worktree" and "config" we need to start using a "ret = ..." return pattern. For "builtin/bugreport.c" these UNLEAK() were added in [4], and for "builtin/config.c" in [1]. For "config" the code seen here was the only user of the "value" variable. For "ACTION_{RENAME,REMOVE}_SECTION" we need to be sure to return the right exit code in the cases where we were relying on falling through to the top-level. I think there's still a use-case for UNLEAK(), but hat it's changed since then. Using it so that "we can see the real leaks" is counter-productive in these cases. It's more useful to have UNLEAK() be a marker of the remaining odd cases where it's hard to free() the memory for whatever reason. With this change less than 20 of them remain in-tree. 1.0e5bba53af
(add UNLEAK annotation for reducing leak false positives, 2017-09-08) 2.d861d34a6e
(worktree: remove extra members from struct add_opts, 2018-04-24) 3.0db4961c49
(worktree: teach `add` to accept --reason <string> with --lock, 2021-07-15) 4.0e5bba53af
and00d8c31105
(commit: fix "author_ident" leak, 2022-05-12). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>
This commit is contained in:

committed by
Junio C Hamano

parent
603f2f5719
commit
ac95f5d36a
@ -1874,8 +1874,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
||||
apply_autostash(git_path_merge_autostash(the_repository));
|
||||
|
||||
cleanup:
|
||||
UNLEAK(author_ident);
|
||||
UNLEAK(err);
|
||||
UNLEAK(sb);
|
||||
strbuf_release(&author_ident);
|
||||
strbuf_release(&err);
|
||||
strbuf_release(&sb);
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user