Commit 979f75d8e1df7e8e43797822d5a55a8eff74fa74

Vicent Marti 2013-05-30T17:19:43

Refcounting

diff --git a/src/refdb.c b/src/refdb.c
index d8daa77..359842e 100644
--- a/src/refdb.c
+++ b/src/refdb.c
@@ -86,7 +86,7 @@ int git_refdb_compress(git_refdb *db)
 	return 0;
 }
 
-static void refdb_free(git_refdb *db)
+void git_refdb__free(git_refdb *db)
 {
 	refdb_free_backend(db);
 	git__free(db);
@@ -97,7 +97,7 @@ void git_refdb_free(git_refdb *db)
 	if (db == NULL)
 		return;
 
-	GIT_REFCOUNT_DEC(db, refdb_free);
+	GIT_REFCOUNT_DEC(db, git_refdb__free);
 }
 
 int git_refdb_exists(int *exists, git_refdb *refdb, const char *ref_name)
@@ -161,7 +161,7 @@ int git_refdb_iterator_next_name(const char **out, git_reference_iterator *iter)
 
 void git_refdb_iterator_free(git_reference_iterator *iter)
 {
-	GIT_REFCOUNT_DEC(iter->db, refdb_free);
+	GIT_REFCOUNT_DEC(iter->db, git_refdb__free);
 	iter->free(iter);
 }
 
diff --git a/src/refdb.h b/src/refdb.h
index 62068db..3aea37b 100644
--- a/src/refdb.h
+++ b/src/refdb.h
@@ -16,6 +16,8 @@ struct git_refdb {
 	git_refdb_backend *backend;
 };
 
+void git_refdb__free(git_refdb *db);
+
 int git_refdb_exists(
 	int *exists,
 	git_refdb *refdb,
diff --git a/src/refs.c b/src/refs.c
index c60e042..7103dec 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -95,6 +95,9 @@ void git_reference_free(git_reference *reference)
 	if (reference->type == GIT_REF_SYMBOLIC)
 		git__free(reference->target.symbolic);
 
+	if (reference->db)
+		GIT_REFCOUNT_DEC(reference->db, git_refdb__free);
+
 	git__free(reference);
 }