Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Commit

Permalink
Work around libgit2 leaks
Browse files Browse the repository at this point in the history
Summary:
EdenFS uses libgit2 with multiple threads. This is supported by libgit2, but `git_libgit2_shutdown` does not clean up per-thread data it allocates. This results in memory leaks.

I discovered this leak while writing D13113450: StartWithRepoTestGit.test_eden_start_mounts_checkouts fails because LSAN reports the following leak from EdenFS:

```
Direct leak of 104 byte(s) in 1 object(s) allocated from:
    #0 0x555f6f in calloc (.../buck-out/dev/gen/eden/fs/service/edenfs+0x555f6f)
    #1 0x7f15d1fd1728 in git__calloc .../libgit2-0.27.5/src/util.h:99:14
    #2 0x7f15d1fd1b10 in git__global_state .../libgit2-0.27.5/src/global.c:330:8
    #3 0x7f15d1fc8b44 in giterr_set .../libgit2-0.27.5/src/errors.c:59:18
    #4 0x7f15d1ff9bad in git_odb__error_notfound .../libgit2-0.27.5/src/odb.c:1539:3
    #5 0x7f15d1ffd579 in pack_entry_find .../libgit2-0.27.5/src/odb_pack.c:271:9
    #6 0x7f15d1ffda32 in pack_backend__read .../libgit2-0.27.5/src/odb_pack.c:400:15
    #7 0x7f15d1ff8911 in odb_read_1 .../libgit2-0.27.5/src/odb.c:1054:12
    #8 0x7f15d1ff8b19 in git_odb_read .../libgit2-0.27.5/src/odb.c:1105:10
    #9 0x7f15d1ff54a2 in git_object_lookup_prefix .../libgit2-0.27.5/src/object.c:169:12
    #10 0x7f15d1ff5570 in git_object_lookup .../libgit2-0.27.5/src/object.c:200:9
    #11 0x7f15d1ff5fff in git_tree_lookup .../libgit2-0.27.5/src/object_api.c:56:9
    #12 0x7f15c43a822a in facebook::eden::GitBackingStore::getTreeImpl(facebook::eden::Hash const&) eden/fs/store/git/GitBackingStore.cpp:88
    #13 0x7f15c43d4daa in facebook::eden::GitBackingStore::getTreeForCommit(facebook::eden::Hash const&)::$_8::operator()(std::unique_ptr<facebook::eden::Tree, std::default_delete<facebook::eden::Tree> >) const eden/fs/store/git/GitBackingStore.cpp:186
```

libgit2 has no API to clean up these allocations. (Note: `giterr_clear` does not free the thread-local error string buffer.). Aside from making EdenFS use libgit2 from one thread or fixing libgit2, we can't do anything about the leaks.

As a workaround, suppress leak reports for allocations from the problematic libgit2 APIs.

Reviewed By: simpkins

Differential Revision: D13163830

fbshipit-source-id: b33e1ca07541442665dab2718aabe9919c44d8b9
  • Loading branch information
Matt Glazar authored and facebook-github-bot committed Nov 27, 2018
1 parent 5cb508b commit f4a949e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions infra_macros/fbcode_macros/build_defs/sanitizers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ _LSAN_DEFAULT_SUPPRESSIONS = [
"/lib/libpython",
"libluajit-5.1.so.2",
"/src/cpython",
# T37141809: libgit2 is leaky in multi-threaded programs.
"giterr_set",
]

_TSAN_DEFAULT_OPTIONS = {
Expand Down

0 comments on commit f4a949e

Please sign in to comment.