From: Junio C Hamano Date: Sat, 7 Oct 2017 07:27:55 +0000 (+0900) Subject: Merge branch 'ma/builtin-unleak' X-Git-Tag: v2.15.0-rc1~19 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/5261fefa4aa7e9c054e1bd664a138d49a3e26d79?ds=inline;hp=-c Merge branch 'ma/builtin-unleak' Many variables that points at a region of memory that will live throughout the life of the program have been marked with UNLEAK marker to help the leak checkers concentrate on real leaks.. * ma/builtin-unleak: builtin/: add UNLEAKs --- 5261fefa4aa7e9c054e1bd664a138d49a3e26d79 diff --combined builtin/checkout.c index 10751585ea,fef94c0223..fc4f8fd2ea --- a/builtin/checkout.c +++ b/builtin/checkout.c @@@ -436,7 -436,6 +436,7 @@@ static int reset_tree(struct tree *tree * update paths in the work tree, and we cannot revert * them. */ + /* fallthrough */ case 0: return 0; default: @@@ -797,14 -796,9 +797,14 @@@ static void orphaned_commit_warning(str for_each_ref(add_pending_uninteresting_ref, &revs); add_pending_oid(&revs, "HEAD", &new->object.oid, UNINTERESTING); + /* Save pending objects, so they can be cleaned up later. */ refs = revs.pending; revs.leak_pending = 1; + /* + * prepare_revision_walk (together with .leak_pending = 1) makes us + * the sole owner of the list of pending objects. + */ if (prepare_revision_walk(&revs)) die(_("internal error in revision walk")); if (!(old->object.flags & UNINTERESTING)) @@@ -812,10 -806,8 +812,10 @@@ else describe_detached_head(_("Previous HEAD position was"), old); + /* Clean up objects used, as they will be reused. */ clear_commit_marks_for_object_array(&refs, ALL_REV_FLAGS); - free(refs.objects); + + object_array_clear(&refs); } static int switch_branches(const struct checkout_opts *opts, @@@ -869,7 -861,7 +869,7 @@@ static int git_checkout_config(const ch } if (starts_with(var, "submodule.")) - return submodule_config(var, value, NULL); + return git_default_submodule_config(var, value, NULL); return git_xmerge_config(var, value, NULL); } @@@ -1124,8 -1116,9 +1124,8 @@@ static int checkout_branch(struct check if (new->path && !opts->force_detach && !opts->new_branch && !opts->ignore_other_worktrees) { - struct object_id oid; int flag; - char *head_ref = resolve_refdup("HEAD", 0, oid.hash, &flag); + char *head_ref = resolve_refdup("HEAD", 0, NULL, &flag); if (head_ref && (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path))) die_if_checked_out(new->path, 1); @@@ -1189,6 -1182,7 +1189,6 @@@ int cmd_checkout(int argc, const char * opts.prefix = prefix; opts.show_progress = -1; - gitmodules_config(); git_config(git_checkout_config, &opts); opts.track = BRANCH_TRACK_UNSPECIFIED; @@@ -1297,6 -1291,7 +1297,7 @@@ strbuf_release(&buf); } + UNLEAK(opts); if (opts.patch_mode || opts.pathspec.nr) return checkout_paths(&opts, new.name); else diff --combined builtin/diff-index.c index 9d772f8f27,09959f254f..522f4fdffd --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@@ -23,6 -23,7 +23,6 @@@ int cmd_diff_index(int argc, const cha git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ init_revisions(&rev, prefix); - gitmodules_config(); rev.abbrev = 0; precompose_argv(argc, argv); @@@ -56,5 -57,6 +56,6 @@@ return -1; } result = run_diff_index(&rev, cached); + UNLEAK(rev); return diff_result_code(&rev.diffopt, result); } diff --combined builtin/diff.c index 7e3ebcea38,0da526cfdb..f5bbd4d757 --- a/builtin/diff.c +++ b/builtin/diff.c @@@ -315,6 -315,8 +315,6 @@@ int cmd_diff(int argc, const char **arg no_index = DIFF_NO_INDEX_IMPLICIT; } - if (!no_index) - gitmodules_config(); init_diff_ui_defaults(); git_config(git_diff_ui_config, NULL); precompose_argv(argc, argv); @@@ -464,5 -466,8 +464,8 @@@ result = diff_result_code(&rev.diffopt, result); if (1 < rev.diffopt.skip_stat_unmatch) refresh_index_quietly(); + UNLEAK(rev); + UNLEAK(ent); + UNLEAK(blob); return result; } diff --combined builtin/name-rev.c index 598da6c8bc,9e584f5da2..9e088ebd11 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@@ -253,7 -253,7 +253,7 @@@ static int name_ref(const char *path, c struct commit *commit = (struct commit *)o; int from_tag = starts_with(path, "refs/tags/"); - if (taggerdate == ULONG_MAX) + if (taggerdate == TIME_MAX) taggerdate = ((struct commit *)o)->date; path = name_ref_abbrev(path, can_abbreviate_output); name_rev(commit, xstrdup(path), taggerdate, 0, 0, @@@ -494,5 -494,6 +494,6 @@@ int cmd_name_rev(int argc, const char * always, allow_undefined, data.name_only); } + UNLEAK(revs); return 0; } diff --combined builtin/tag.c index c627794181,14d1583cff..34efba5798 --- a/builtin/tag.c +++ b/builtin/tag.c @@@ -113,7 -113,7 +113,7 @@@ static int verify_tag(const char *name if (format->format) flags = GPG_VERIFY_OMIT_STATUS; - if (gpg_verify_tag(oid->hash, name, flags)) + if (gpg_verify_tag(oid, name, flags)) return -1; if (format->format) @@@ -552,9 -552,10 +552,10 @@@ int cmd_tag(int argc, const char **argv if (force && !is_null_oid(&prev) && oidcmp(&prev, &object)) printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev.hash, DEFAULT_ABBREV)); - strbuf_release(&err); - strbuf_release(&buf); - strbuf_release(&ref); - strbuf_release(&reflog_msg); + UNLEAK(buf); + UNLEAK(ref); + UNLEAK(reflog_msg); + UNLEAK(msg); + UNLEAK(err); return 0; }