Skip to content

Commit 4f66c83

Browse files
dschogitster
authored andcommitted
sequencer: roll back lock file if write_message() failed
There is no need to wait until the atexit() handler kicks in at the end. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 452202c commit 4f66c83

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sequencer.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,14 @@ static int write_message(struct strbuf *msgbuf, const char *filename)
241241
int msg_fd = hold_lock_file_for_update(&msg_file, filename, 0);
242242
if (msg_fd < 0)
243243
return error_errno(_("Could not lock '%s'"), filename);
244-
if (write_in_full(msg_fd, msgbuf->buf, msgbuf->len) < 0)
245-
return error_errno(_("Could not write to %s"), filename);
246-
if (commit_lock_file(&msg_file) < 0)
244+
if (write_in_full(msg_fd, msgbuf->buf, msgbuf->len) < 0) {
245+
rollback_lock_file(&msg_file);
246+
return error_errno(_("Could not write to '%s'"), filename);
247+
}
248+
if (commit_lock_file(&msg_file) < 0) {
249+
rollback_lock_file(&msg_file);
247250
return error(_("Error wrapping up %s."), filename);
251+
}
248252

249253
return 0;
250254
}

0 commit comments

Comments
 (0)