@@ -2450,7 +2450,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
24502450{
24512451 int fd = -1 , in_fd = -1 ;
24522452 int ret ;
2453- struct lock_file * lock = NULL ;
2453+ static struct lock_file lock ;
24542454 char * filename_buf = NULL ;
24552455 char * contents = NULL ;
24562456 size_t contents_sz ;
@@ -2469,8 +2469,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
24692469 * The lock serves a purpose in addition to locking: the new
24702470 * contents of .git/config will be written into it.
24712471 */
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 );
24742473 if (fd < 0 ) {
24752474 error_errno ("could not lock config file %s" , config_filename );
24762475 free (store .key );
@@ -2583,8 +2582,8 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
25832582 close (in_fd );
25842583 in_fd = -1 ;
25852584
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 ));
25882587 ret = CONFIG_NO_WRITE ;
25892588 goto out_free ;
25902589 }
@@ -2639,28 +2638,19 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
26392638 contents = NULL ;
26402639 }
26412640
2642- if (commit_lock_file (lock ) < 0 ) {
2641+ if (commit_lock_file (& lock ) < 0 ) {
26432642 error_errno ("could not write config file %s" , config_filename );
26442643 ret = CONFIG_NO_WRITE ;
2645- lock = NULL ;
26462644 goto out_free ;
26472645 }
26482646
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 ;
26562647 ret = 0 ;
26572648
26582649 /* Invalidate the config cache */
26592650 git_config_clear ();
26602651
26612652out_free :
2662- if (lock )
2663- rollback_lock_file (lock );
2653+ rollback_lock_file (& lock );
26642654 free (filename_buf );
26652655 if (contents )
26662656 munmap (contents , contents_sz );
@@ -2669,7 +2659,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
26692659 return ret ;
26702660
26712661write_err_out :
2672- ret = write_error (get_lock_file_path (lock ));
2662+ ret = write_error (get_lock_file_path (& lock ));
26732663 goto out_free ;
26742664
26752665}
0 commit comments