aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-09-13 15:27:42 -0700
committerJunio C Hamano <gitster@pobox.com>2024-09-13 15:27:43 -0700
commit17ae0b824911640dcccda9ff2f3a312ebe9dbacb (patch)
tree3bf2bfe687443eed26136cf766f5480866c04319
parent0299251319669eba8c343f56c4bd5393148674da (diff)
parenta71c47825d2650cfe53217d860107d9457cc375c (diff)
downloadgit-17ae0b824911640dcccda9ff2f3a312ebe9dbacb.tar.gz
Merge branch 'jk/sparse-fdleak-fix'
A file descriptor left open is now properly closed when "git sparse-checkout" updates the sparse patterns. * jk/sparse-fdleak-fix: sparse-checkout: use fdopen_lock_file() instead of xfdopen() sparse-checkout: check commit_lock_file when writing patterns sparse-checkout: consolidate cleanup when writing patterns
-rw-r--r--builtin/sparse-checkout.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 2604ab04df..5ccf696862 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -327,7 +327,6 @@ static int write_patterns_and_update(struct pattern_list *pl)
{
char *sparse_filename;
FILE *fp;
- int fd;
struct lock_file lk = LOCK_INIT;
int result;
@@ -336,31 +335,31 @@ static int write_patterns_and_update(struct pattern_list *pl)
if (safe_create_leading_directories(sparse_filename))
die(_("failed to create directory for sparse-checkout file"));
- fd = hold_lock_file_for_update(&lk, sparse_filename,
- LOCK_DIE_ON_ERROR);
- free(sparse_filename);
+ hold_lock_file_for_update(&lk, sparse_filename, LOCK_DIE_ON_ERROR);
result = update_working_directory(pl);
if (result) {
rollback_lock_file(&lk);
- clear_pattern_list(pl);
update_working_directory(NULL);
- return result;
+ goto out;
}
- fp = xfdopen(fd, "w");
+ fp = fdopen_lock_file(&lk, "w");
+ if (!fp)
+ die_errno(_("unable to fdopen %s"), get_lock_file_path(&lk));
if (core_sparse_checkout_cone)
write_cone_to_file(fp, pl);
else
write_patterns_to_file(fp, pl);
- fflush(fp);
- commit_lock_file(&lk);
+ if (commit_lock_file(&lk))
+ die_errno(_("unable to write %s"), sparse_filename);
+out:
clear_pattern_list(pl);
-
- return 0;
+ free(sparse_filename);
+ return result;
}
enum sparse_checkout_mode {