summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlhchavez <[email protected]>2020-06-21 06:44:06 -0700
committerGitHub <[email protected]>2020-06-21 06:44:06 -0700
commit619a9c236bf79c63d955490c0803833004a47154 (patch)
treef855ae2693c23786852e7be85b7213045000ebe5
parent9eaf4fed5f4f2361898f9da8345b34886076bfc2 (diff)
Add a way to cleanly shut down the library (#578)
This change adds the Shutdown() method, so that the library can be cleanly shut down. This helps significanly reduce the amount of noise in the leak detector.
-rw-r--r--git.go10
-rw-r--r--handles.go10
2 files changed, 20 insertions, 0 deletions
diff --git a/git.go b/git.go
index 0459dde..bd01b6d 100644
--- a/git.go
+++ b/git.go
@@ -139,6 +139,16 @@ func init() {
C.git_openssl_set_locking()
}
+// Shutdown frees all the resources acquired by libgit2. Make sure no
+// references to any git2go objects are live before calling this.
+// After this is called, invoking any function from this library will result in
+// undefined behavior, so make sure this is called carefully.
+func Shutdown() {
+ pointerHandles.Clear()
+
+ C.git_libgit2_shutdown()
+}
+
// Oid represents the id for a Git object.
type Oid [20]byte
diff --git a/handles.go b/handles.go
index d27d3c3..c0d4b3c 100644
--- a/handles.go
+++ b/handles.go
@@ -43,6 +43,16 @@ func (v *HandleList) Untrack(handle unsafe.Pointer) {
v.Unlock()
}
+// Clear stops tracking all the managed pointers.
+func (v *HandleList) Clear() {
+ v.Lock()
+ for handle := range v.handles {
+ delete(v.handles, handle)
+ C.free(handle)
+ }
+ v.Unlock()
+}
+
// Get retrieves the pointer from the given handle
func (v *HandleList) Get(handle unsafe.Pointer) interface{} {
v.RLock()