Merge branch 'ma/builtin-unleak'
authorJunio C Hamano <gitster@pobox.com>
Sat, 7 Oct 2017 07:27:55 +0000 (16:27 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sat, 7 Oct 2017 07:27:55 +0000 (16:27 +0900)
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

1  2 
builtin/checkout.c
builtin/diff-index.c
builtin/diff.c
builtin/name-rev.c
builtin/tag.c
diff --combined builtin/checkout.c
index 10751585ea38c282d439e4128c895c01a2598985,fef94c0223fb90755d1bb19408c7fdd4e556dd69..fc4f8fd2ea29c7c23d3b1c7ca0ba78824c255a91
@@@ -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))
        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;
                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 9d772f8f27fe722921c00ea57af1087f988856da,09959f254fc3ea129ae834df404d21c6be7bee3d..522f4fdffd064de2e50232934cb7d616246c92e4
@@@ -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 7e3ebcea38f1485f4c7fb5f5af6494ceb81f5cbb,0da526cfdb893dbfeaae774edeb75cd244fb7e6e..f5bbd4d757e12e6e34a86fac006298acb771909f
@@@ -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);
        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 598da6c8bc75e9de50f85eac78d3051f27f96a6c,9e584f5da26ec629e77566f16bff9b5372174775..9e088ebd11dced248640df9e17adbbd8b9a73ffb
@@@ -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 c627794181f55d293719e5369d74bb9b598f5450,14d1583cff579a8a397808b9f10fd521e4055682..34efba5798e226f684906af74ebbc104e8401f39
@@@ -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;
  }