From: Michael Haggerty Date: Wed, 1 Oct 2014 10:28:12 +0000 (+0200) Subject: hold_lock_file_for_append(): release lock on errors X-Git-Tag: v2.2.0-rc0~53^2~30 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ebb8e380e98e83f32c1cc04200d3749ab4c0b90a hold_lock_file_for_append(): release lock on errors If there is an error copying the old contents to the lockfile, roll back the lockfile before exiting so that the lockfile is not held until process cleanup. Signed-off-by: Michael Haggerty Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- diff --git a/lockfile.c b/lockfile.c index d74de8d329..f4ce79bc27 100644 --- a/lockfile.c +++ b/lockfile.c @@ -219,13 +219,13 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags) if (errno != ENOENT) { if (flags & LOCK_DIE_ON_ERROR) die("cannot open '%s' for copying", path); - close(fd); + rollback_lock_file(lk); return error("cannot open '%s' for copying", path); } } else if (copy_fd(orig_fd, fd)) { if (flags & LOCK_DIE_ON_ERROR) exit(128); - close(fd); + rollback_lock_file(lk); return -1; } return fd;