Merge branch 'jk/config-lockfile-leak-fix' into maint
A leakfix. * jk/config-lockfile-leak-fix: config: use a static lock_file structmaint
commit
96d14cbb91
24
config.c
24
config.c
|
@ -2404,7 +2404,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
|
||||||
{
|
{
|
||||||
int fd = -1, in_fd = -1;
|
int fd = -1, in_fd = -1;
|
||||||
int ret;
|
int ret;
|
||||||
struct lock_file *lock = NULL;
|
static struct lock_file lock;
|
||||||
char *filename_buf = NULL;
|
char *filename_buf = NULL;
|
||||||
char *contents = NULL;
|
char *contents = NULL;
|
||||||
size_t contents_sz;
|
size_t contents_sz;
|
||||||
|
@ -2423,8 +2423,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
|
||||||
* The lock serves a purpose in addition to locking: the new
|
* The lock serves a purpose in addition to locking: the new
|
||||||
* contents of .git/config will be written into it.
|
* contents of .git/config will be written into it.
|
||||||
*/
|
*/
|
||||||
lock = xcalloc(1, sizeof(struct lock_file));
|
fd = hold_lock_file_for_update(&lock, config_filename, 0);
|
||||||
fd = hold_lock_file_for_update(lock, config_filename, 0);
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
error_errno("could not lock config file %s", config_filename);
|
error_errno("could not lock config file %s", config_filename);
|
||||||
free(store.key);
|
free(store.key);
|
||||||
|
@ -2537,8 +2536,8 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
|
||||||
close(in_fd);
|
close(in_fd);
|
||||||
in_fd = -1;
|
in_fd = -1;
|
||||||
|
|
||||||
if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
|
if (chmod(get_lock_file_path(&lock), st.st_mode & 07777) < 0) {
|
||||||
error_errno("chmod on %s failed", get_lock_file_path(lock));
|
error_errno("chmod on %s failed", get_lock_file_path(&lock));
|
||||||
ret = CONFIG_NO_WRITE;
|
ret = CONFIG_NO_WRITE;
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
@ -2593,28 +2592,19 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
|
||||||
contents = NULL;
|
contents = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commit_lock_file(lock) < 0) {
|
if (commit_lock_file(&lock) < 0) {
|
||||||
error_errno("could not write config file %s", config_filename);
|
error_errno("could not write config file %s", config_filename);
|
||||||
ret = CONFIG_NO_WRITE;
|
ret = CONFIG_NO_WRITE;
|
||||||
lock = NULL;
|
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* lock is committed, so don't try to roll it back below.
|
|
||||||
* NOTE: Since lockfile.c keeps a linked list of all created
|
|
||||||
* lock_file structures, it isn't safe to free(lock). It's
|
|
||||||
* better to just leave it hanging around.
|
|
||||||
*/
|
|
||||||
lock = NULL;
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
/* Invalidate the config cache */
|
/* Invalidate the config cache */
|
||||||
git_config_clear();
|
git_config_clear();
|
||||||
|
|
||||||
out_free:
|
out_free:
|
||||||
if (lock)
|
rollback_lock_file(&lock);
|
||||||
rollback_lock_file(lock);
|
|
||||||
free(filename_buf);
|
free(filename_buf);
|
||||||
if (contents)
|
if (contents)
|
||||||
munmap(contents, contents_sz);
|
munmap(contents, contents_sz);
|
||||||
|
@ -2623,7 +2613,7 @@ out_free:
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
write_err_out:
|
write_err_out:
|
||||||
ret = write_error(get_lock_file_path(lock));
|
ret = write_error(get_lock_file_path(&lock));
|
||||||
goto out_free;
|
goto out_free;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue