handle non-existent reference in got_ref_resolve() error path
diff --git a/lib/reference.c b/lib/reference.c
index 0a2b43b..f01bb78 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -511,7 +511,8 @@ got_ref_resolve(struct got_object_id **id, struct got_repository *repo,
err = resolve_symbolic_ref(&resolved, repo, ref);
if (err == NULL)
err = got_ref_resolve(id, repo, resolved);
- got_ref_close(resolved);
+ if (resolved)
+ got_ref_close(resolved);
return err;
}