]> git.ipfire.org Git - thirdparty/git.git/commit - bundle.c
create_bundle(): duplicate file descriptor to avoid closing it twice
authorMichael Haggerty <mhagger@alum.mit.edu>
Mon, 10 Aug 2015 09:47:37 +0000 (11:47 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Aug 2015 19:57:14 +0000 (12:57 -0700)
commite54c347c1c444c0f37b64b8735c50a66ee0527e9
tree02d2fc2f4952cf510273ad357afec5efd8c81641
parent2db69de81deea4682579d0b9e6da40b4e9558c05
create_bundle(): duplicate file descriptor to avoid closing it twice

write_pack_data() passes bundle_fd to start_command() to be used as
the stdout of pack-objects. But start_command() closes its stdout if
it is > 1. This is a problem if bundle_fd is the fd of a lock_file,
because commit_lock_file() will also try to close the fd.

So the old code suppressed commit_lock_file()'s usual behavior of
closing the file descriptor by setting the lock_file object's fd field
to -1.

But this is not really kosher. Code here shouldn't be mutating fields
within the lock_file object.

Instead, duplicate the file descriptor before passing it to
write_pack_data(). Then that function can close its copy without
closing the copy held in the lock_file object.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
bundle.c