Commit e2a80124 by Etienne Samson Committed by Patrick Steinhardt

refs: preserve the owning refdb when duping reference

This fixes a segfault in git_reference_owner on references returned from git_reference__read_head and git_reference_dup ones.
parent e9ee7bd0
......@@ -115,6 +115,9 @@ int git_reference_dup(git_reference **dest, git_reference *source)
GITERR_CHECK_ALLOC(*dest);
(*dest)->db = source->db;
GIT_REFCOUNT_INC((*dest)->db);
return 0;
}
......
......@@ -116,6 +116,10 @@ int git_reference_lookup_resolved(
* with the given name pointing to the reference pointed to by
* the file. If it is not a symbolic reference, it will return
* the resolved reference.
*
* Note that because the refdb is not involved for symbolic references, they
* won't be owned, hence you should either not make the returned reference
* 'externally visible', or perform the lookup before returning it to the user.
*/
int git_reference__read_head(
git_reference **out,
......
......@@ -21,6 +21,7 @@ void test_refs_dup__direct(void)
cl_git_pass(git_reference_dup(&b, a));
cl_assert(git_reference_cmp(a, b) == 0);
cl_assert(git_reference_owner(b) == g_repo);
git_reference_free(b);
git_reference_free(a);
......@@ -34,6 +35,7 @@ void test_refs_dup__symbolic(void)
cl_git_pass(git_reference_dup(&b, a));
cl_assert(git_reference_cmp(a, b) == 0);
cl_assert(git_reference_owner(b) == g_repo);
git_reference_free(b);
git_reference_free(a);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment