@@ -2408,7 +2408,8 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2408
2408
unsigned int flags , int * type_p ,
2409
2409
struct strbuf * err )
2410
2410
{
2411
- const char * ref_file ;
2411
+ struct strbuf ref_file = STRBUF_INIT ;
2412
+ struct strbuf orig_ref_file = STRBUF_INIT ;
2412
2413
const char * orig_refname = refname ;
2413
2414
struct ref_lock * lock ;
2414
2415
int last_errno = 0 ;
@@ -2432,20 +2433,19 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2432
2433
refname = resolve_ref_unsafe (refname , resolve_flags ,
2433
2434
lock -> old_oid .hash , & type );
2434
2435
if (!refname && errno == EISDIR ) {
2435
- /* we are trying to lock foo but we used to
2436
+ /*
2437
+ * we are trying to lock foo but we used to
2436
2438
* have foo/bar which now does not exist;
2437
2439
* it is normal for the empty directory 'foo'
2438
2440
* to remain.
2439
2441
*/
2440
- ref_file = git_path ( "%s" , orig_refname );
2441
- if (remove_empty_directories (ref_file )) {
2442
+ strbuf_git_path ( & orig_ref_file , "%s" , orig_refname );
2443
+ if (remove_empty_directories (orig_ref_file . buf )) {
2442
2444
last_errno = errno ;
2443
-
2444
2445
if (!verify_refname_available (orig_refname , extras , skip ,
2445
2446
get_loose_refs (& ref_cache ), err ))
2446
2447
strbuf_addf (err , "there are still refs under '%s'" ,
2447
2448
orig_refname );
2448
-
2449
2449
goto error_return ;
2450
2450
}
2451
2451
refname = resolve_ref_unsafe (orig_refname , resolve_flags ,
@@ -2485,10 +2485,10 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2485
2485
}
2486
2486
lock -> ref_name = xstrdup (refname );
2487
2487
lock -> orig_ref_name = xstrdup (orig_refname );
2488
- ref_file = git_path ( "%s" , refname );
2488
+ strbuf_git_path ( & ref_file , "%s" , refname );
2489
2489
2490
2490
retry :
2491
- switch (safe_create_leading_directories_const (ref_file )) {
2491
+ switch (safe_create_leading_directories_const (ref_file . buf )) {
2492
2492
case SCLD_OK :
2493
2493
break ; /* success */
2494
2494
case SCLD_VANISHED :
@@ -2497,11 +2497,12 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2497
2497
/* fall through */
2498
2498
default :
2499
2499
last_errno = errno ;
2500
- strbuf_addf (err , "unable to create directory for %s" , ref_file );
2500
+ strbuf_addf (err , "unable to create directory for %s" ,
2501
+ ref_file .buf );
2501
2502
goto error_return ;
2502
2503
}
2503
2504
2504
- if (hold_lock_file_for_update (lock -> lk , ref_file , lflags ) < 0 ) {
2505
+ if (hold_lock_file_for_update (lock -> lk , ref_file . buf , lflags ) < 0 ) {
2505
2506
last_errno = errno ;
2506
2507
if (errno == ENOENT && -- attempts_remaining > 0 )
2507
2508
/*
@@ -2511,20 +2512,25 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2511
2512
*/
2512
2513
goto retry ;
2513
2514
else {
2514
- unable_to_lock_message (ref_file , errno , err );
2515
+ unable_to_lock_message (ref_file . buf , errno , err );
2515
2516
goto error_return ;
2516
2517
}
2517
2518
}
2518
2519
if (old_sha1 && verify_lock (lock , old_sha1 , mustexist , err )) {
2519
2520
last_errno = errno ;
2520
2521
goto error_return ;
2521
2522
}
2522
- return lock ;
2523
+ goto out ;
2523
2524
2524
2525
error_return :
2525
2526
unlock_ref (lock );
2527
+ lock = NULL ;
2528
+
2529
+ out :
2530
+ strbuf_release (& ref_file );
2531
+ strbuf_release (& orig_ref_file );
2526
2532
errno = last_errno ;
2527
- return NULL ;
2533
+ return lock ;
2528
2534
}
2529
2535
2530
2536
/*
0 commit comments