@@ -199,6 +199,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
199199 uintmax_t pid ;
200200 FILE * fp ;
201201 int fd ;
202+ char * pidfile_path ;
202203
203204 if (pidfile )
204205 /* already locked */
@@ -207,12 +208,13 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
207208 if (gethostname (my_host , sizeof (my_host )))
208209 strcpy (my_host , "unknown" );
209210
210- fd = hold_lock_file_for_update (& lock , git_path ("gc.pid" ),
211+ pidfile_path = git_pathdup ("gc.pid" );
212+ fd = hold_lock_file_for_update (& lock , pidfile_path ,
211213 LOCK_DIE_ON_ERROR );
212214 if (!force ) {
213215 static char locking_host [128 ];
214216 int should_exit ;
215- fp = fopen (git_path ( "gc.pid" ) , "r" );
217+ fp = fopen (pidfile_path , "r" );
216218 memset (locking_host , 0 , sizeof (locking_host ));
217219 should_exit =
218220 fp != NULL &&
@@ -236,6 +238,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
236238 if (fd >= 0 )
237239 rollback_lock_file (& lock );
238240 * ret_pid = pid ;
241+ free (pidfile_path );
239242 return locking_host ;
240243 }
241244 }
@@ -246,7 +249,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
246249 strbuf_release (& sb );
247250 commit_lock_file (& lock );
248251
249- pidfile = git_pathdup ( "gc.pid" ) ;
252+ pidfile = pidfile_path ;
250253 sigchain_push_common (remove_pidfile_on_signal );
251254 atexit (remove_pidfile );
252255
0 commit comments