)]}'
{
  "commit": "e4de4502e6e32d5ce71fa6fcfc0703a4be411eb7",
  "tree": "bc450256a8e7eba2a8e564f1d32489cd8495f7d5",
  "parents": [
    "aa1b63971ab4e7d1f603c87f2137605249580272"
  ],
  "author": {
    "name": "Andrzej Hunt",
    "email": "ajrhunt@google.com",
    "time": "Sun Mar 14 18:47:38 2021 +0000"
  },
  "committer": {
    "name": "Junio C Hamano",
    "email": "gitster@pobox.com",
    "time": "Sun Mar 14 15:57:59 2021 -0700"
  },
  "message": "init: remove git_init_db_config() while fixing leaks\n\nThe primary goal of this change is to stop leaking init_db_template_dir.\nThis leak can happen because:\n 1. git_init_db_config() allocates new memory into init_db_template_dir\n    without first freeing the existing value.\n 2. init_db_template_dir might already contain data, either because:\n  2.1 git_config() can be invoked twice with this callback in a single\n      process - at least 2 allocations are likely.\n  2.2 A single git_config() allocation can invoke the callback multiple\n      times for a given key (see further explanation in the function\n      docs) - each of those calls will trigger another leak.\n\nThe simplest fix for the leak would be to free(init_db_template_dir)\nbefore overwriting it. Instead we choose to convert to fetching\ninit.templatedir via git_config_get_value() as that is more explicit,\nmore efficient, and avoids allocations (the returned result is owned by\nthe config cache, so we aren\u0027t responsible for freeing it).\n\nIf we remove init_db_template_dir, git_init_db_config() ends up being\nresponsible only for forwarding core.* config values to\nplatform_core_config(). However platform_core_config() already ignores\nnon-core.* config values, so we can safely remove git_init_db_config()\nand invoke git_config() directly with platform_core_config() as the\ncallback.\n\nThe platform_core_config forwarding was originally added in:\n  287853392a (mingw: respect core.hidedotfiles \u003d false in git-init again, 2019-03-11\nAnd I suspect the potential for a leak existed since the original\nimplementation of git_init_db_config in:\n  90b45187ba (Add `init.templatedir` configuration variable., 2010-02-17)\n\nLSAN output from t0001:\n\nDirect leak of 73 byte(s) in 1 object(s) allocated from:\n    #0 0x49a859 in realloc /home/abuild/rpmbuild/BUILD/llvm-11.0.0.src/build/../projects/compiler-rt/lib/asan/asan_malloc_linux.cpp:164:3\n    #1 0x9a7276 in xrealloc /home/ahunt/oss-fuzz/git/wrapper.c:126:8\n    #2 0x9362ad in strbuf_grow /home/ahunt/oss-fuzz/git/strbuf.c:98:2\n    #3 0x936eaa in strbuf_add /home/ahunt/oss-fuzz/git/strbuf.c:295:2\n    #4 0x868112 in strbuf_addstr /home/ahunt/oss-fuzz/git/./strbuf.h:304:2\n    #5 0x86a8ad in expand_user_path /home/ahunt/oss-fuzz/git/path.c:758:2\n    #6 0x720bb1 in git_config_pathname /home/ahunt/oss-fuzz/git/config.c:1287:10\n    #7 0x5960e2 in git_init_db_config /home/ahunt/oss-fuzz/git/builtin/init-db.c:161:11\n    #8 0x7255b8 in configset_iter /home/ahunt/oss-fuzz/git/config.c:1982:7\n    #9 0x7253fc in repo_config /home/ahunt/oss-fuzz/git/config.c:2311:2\n    #10 0x725ca7 in git_config /home/ahunt/oss-fuzz/git/config.c:2399:2\n    #11 0x593e8d in create_default_files /home/ahunt/oss-fuzz/git/builtin/init-db.c:225:2\n    #12 0x5935c6 in init_db /home/ahunt/oss-fuzz/git/builtin/init-db.c:449:11\n    #13 0x59588e in cmd_init_db /home/ahunt/oss-fuzz/git/builtin/init-db.c:714:9\n    #14 0x4cd60d in run_builtin /home/ahunt/oss-fuzz/git/git.c:453:11\n    #15 0x4cb2da in handle_builtin /home/ahunt/oss-fuzz/git/git.c:704:3\n    #16 0x4ccc37 in run_argv /home/ahunt/oss-fuzz/git/git.c:771:4\n    #17 0x4cac29 in cmd_main /home/ahunt/oss-fuzz/git/git.c:902:19\n    #18 0x69c4de in main /home/ahunt/oss-fuzz/git/common-main.c:52:11\n    #19 0x7f23552d6349 in __libc_start_main (/lib64/libc.so.6+0x24349)\n\nSigned-off-by: Andrzej Hunt \u003cajrhunt@google.com\u003e\nSigned-off-by: Junio C Hamano \u003cgitster@pobox.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "dcc45bef5148117c4b0c3180fcbd94d9f099a1cc",
      "old_mode": 33188,
      "old_path": "builtin/init-db.c",
      "new_id": "d31dbc88374653ca51a946a54fa7b81e9faf907c",
      "new_mode": 33188,
      "new_path": "builtin/init-db.c"
    }
  ]
}
