Skip to content

Commit 49fb937

Browse files
dschogitster
authored andcommitted
sequencer: ensure to release the lock when we could not read the index
A future caller of read_and_refresh_cache() may want to do more than just print some helpful advice in case of failure. Suggested by Junio Hamano. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 55f5704 commit 49fb937

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

sequencer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,14 +644,18 @@ static int read_and_refresh_cache(struct replay_opts *opts)
644644
{
645645
static struct lock_file index_lock;
646646
int index_fd = hold_locked_index(&index_lock, 0);
647-
if (read_index_preload(&the_index, NULL) < 0)
647+
if (read_index_preload(&the_index, NULL) < 0) {
648+
rollback_lock_file(&index_lock);
648649
return error(_("git %s: failed to read the index"),
649650
action_name(opts));
651+
}
650652
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
651653
if (the_index.cache_changed && index_fd >= 0) {
652-
if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
654+
if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) {
655+
rollback_lock_file(&index_lock);
653656
return error(_("git %s: failed to refresh the index"),
654657
action_name(opts));
658+
}
655659
}
656660
rollback_lock_file(&index_lock);
657661
return 0;

0 commit comments

Comments
 (0)