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 <mhagger@alum.mit.edu> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Oct 1, 2014 at 12:28 UTC
ebb8e380e98e83f32c1cc04200d3749ab4c0b90a
1 file changed
+2
-2
lockfile.c
+2
-2
@@ -219,13 +219,13 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags)
219
if (errno != ENOENT) {
220
if (flags & LOCK_DIE_ON_ERROR)
221
die("cannot open '%s' for copying", path);
222
- close(fd);
222
+ rollback_lock_file(lk);
223
return error("cannot open '%s' for copying", path);
224
}
225
} else if (copy_fd(orig_fd, fd)) {
226
if (flags & LOCK_DIE_ON_ERROR)
227
exit(128);
228
- close(fd);
228
+ rollback_lock_file(lk);
229
return -1;
230
}
231
return fd;