commit - 27a1ed032f37a6bf70d5bdabd452600125aa7d18
commit + 505287bea16696d4be0e66f0d9c1db6eafea9fb6
blob - a5ab53c09881abdd830f890c91ced4ca4bb61152
blob + b90b966fcf07c54227e67486dcda744d603bdc2e
--- lib/reference.c
+++ lib/reference.c
}
static const struct got_error *
-insert_ref(struct got_reflist_head *refs, struct got_reference *ref,
- struct got_repository *repo)
+insert_ref(struct got_reflist_entry **newp, struct got_reflist_head *refs,
+ struct got_reference *ref, struct got_repository *repo)
{
const struct got_error *err;
struct got_object_id *id;
struct got_reflist_entry *new, *re, *prev;
int cmp;
+ *newp = NULL;
+
err = got_ref_resolve(&id, repo, ref);
if (err)
return err;
}
new->ref = ref;
new->id = id;
+ *newp = new;
/*
* We must de-duplicate entries on insert because packed-refs may
/* duplicate */
free(new->id);
free(new);
+ *newp = NULL;
return NULL;
} else if (cmp > 0) {
if (prev)
if (err)
goto done;
if (ref) {
- err = insert_ref(refs, ref, repo);
+ struct got_reflist_entry *new;
+ err = insert_ref(&new, refs, ref, repo);
+ if (err || new == NULL /* duplicate */)
+ got_ref_close(ref);
if (err)
goto done;
}
char *packed_refs_path, *path_refs = NULL;
FILE *f = NULL;
struct got_reference *ref;
+ struct got_reflist_entry *new;
/* HEAD ref should always exist. */
path_refs = get_refs_dir_path(repo, GOT_REF_HEAD);
err = open_ref(&ref, path_refs, "", GOT_REF_HEAD);
if (err)
goto done;
- err = insert_ref(refs, ref, repo);
+ err = insert_ref(&new, refs, ref, repo);
+ if (err || new == NULL /* duplicate */)
+ got_ref_close(ref);
if (err)
goto done;
if (err)
goto done;
if (ref) {
- err = insert_ref(refs, ref, repo);
+ err = insert_ref(&new, refs, ref, repo);
+ if (err || new == NULL /* duplicate */)
+ got_ref_close(ref);
if (err)
goto done;
}