fix(refdb): check loose ref allocation failures

The loose ref lookup helper was exposed by 7f35dc581
and then used by b17ecb23e directly for pseudoref lookup.

While investigating the pseudoref owner regression,
I found that the helper also returns success
with a NULL output reference when `git_reference__alloc()`
or `git_reference__alloc_symbolic()` failed.

This fixes it by reporting allocation failures inside
`git_reference__lookup_loose`.
This commit is contained in:
Weihang Lo
2026-04-22 17:43:59 -04:00
parent 735bb2e2f5
commit 7a9b284302

View File

@@ -524,14 +524,20 @@ int git_reference__lookup_loose(
if (!(target = loose_parse_symbolic(&buf)))
error = -1;
else if (out != NULL)
else if (out != NULL) {
*out = git_reference__alloc_symbolic(ref_name, target);
if (*out == NULL)
error = -1;
}
} else {
git_oid oid;
if (!(error = loose_parse_oid(&oid, ref_name, &buf, oid_type)) &&
out != NULL)
out != NULL) {
*out = git_reference__alloc(ref_name, &oid, NULL);
if (*out == NULL)
error = -1;
}
}
git_str_dispose(&buf);