2450
{
2451
int fd = -1, in_fd = -1;
2452
int ret;
2453
- struct lock_file *lock = NULL;
2453
+ struct lock_file lock = LOCK_INIT;
2454
char *filename_buf = NULL;
2455
char *contents = NULL;
2456
size_t contents_sz;
2469
* The lock serves a purpose in addition to locking: the new
2470
* contents of .git/config will be written into it.
2471
*/
2472
- lock = xcalloc(1, sizeof(struct lock_file));
2473
- fd = hold_lock_file_for_update(lock, config_filename, 0);
2472
+ fd = hold_lock_file_for_update(&lock, config_filename, 0);
2473
if (fd < 0) {
2474
error_errno("could not lock config file %s", config_filename);
2475
free(store.key);
2582
close(in_fd);
2583
in_fd = -1;
2584
2586
- if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
2587
- error_errno("chmod on %s failed", get_lock_file_path(lock));
2585
+ if (chmod(get_lock_file_path(&lock), st.st_mode & 07777) < 0) {
2586
+ error_errno("chmod on %s failed", get_lock_file_path(&lock));
2587
ret = CONFIG_NO_WRITE;
2588
goto out_free;
2589
}
2638
contents = NULL;
2639
}
2640
2642
- if (commit_lock_file(lock) < 0) {
2641
+ if (commit_lock_file(&lock) < 0) {
2642
error_errno("could not write config file %s", config_filename);
2643
ret = CONFIG_NO_WRITE;
2645
- lock = NULL;
2644
goto out_free;
2645
}
2646
2649
- /*
2650
- * lock is committed, so don't try to roll it back below.
2651
- * NOTE: Since lockfile.c keeps a linked list of all created
2652
- * lock_file structures, it isn't safe to free(lock). It's
2653
- * better to just leave it hanging around.
2654
- */
2655
- lock = NULL;
2647
ret = 0;
2648
2649
/* Invalidate the config cache */
2650
git_config_clear();
2651
2652
out_free:
2662
- if (lock)
2663
- rollback_lock_file(lock);
2653
+ rollback_lock_file(&lock);
2654
free(filename_buf);
2655
if (contents)
2656
munmap(contents, contents_sz);
2659
return ret;
2660
2661
write_err_out:
2672
- ret = write_error(get_lock_file_path(lock));
2662
+ ret = write_error(get_lock_file_path(&lock));
2663
goto out_free;
2664
2665
}