]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hold_lock_file_for_append(): release lock on errors
authorMichael Haggerty <mhagger@alum.mit.edu>
Wed, 1 Oct 2014 10:28:12 +0000 (12:28 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Oct 2014 20:38:42 +0000 (13:38 -0700)
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>
lockfile.c

index d74de8d329a4adc3e9c2b158365292c36a37a10d..f4ce79bc2733b44d85ddb60c65bb710536747330 100644 (file)
@@ -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;