Skip to content

Commit

Permalink
Merge branch 'jk/sparse-fdleak-fix' into seen
Browse files Browse the repository at this point in the history
* jk/sparse-fdleak-fix:
  SQUASH???
  sparse-checkout: use fdopen_lock_file() instead of xfdopen()
  • Loading branch information
gitster committed Sep 5, 2024
2 parents 436747c + da1cc2a commit 3326bbc
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions builtin/sparse-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,40 +328,41 @@ 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;
int result = 0;

sparse_filename = get_sparse_checkout_filename();

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"), sparse_filename);

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);

clear_pattern_list(pl);

return 0;
out:
free(sparse_filename);
return result;
}

enum sparse_checkout_mode {
Expand Down

0 comments on commit 3326bbc

Please sign in to comment.