@@ -2756,7 +2756,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
27562756 struct strbuf referent = STRBUF_INIT ;
27572757 int mustexist = (update -> flags & REF_HAVE_OLD ) &&
27582758 !is_null_oid (& update -> old_oid );
2759- int ret ;
2759+ int ret = 0 ;
27602760 struct ref_lock * lock ;
27612761
27622762 files_assert_main_repository (refs , "lock_ref_for_update" );
@@ -2768,7 +2768,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
27682768 ret = split_head_update (update , transaction , head_ref ,
27692769 affected_refnames , err );
27702770 if (ret )
2771- return ret ;
2771+ goto out ;
27722772 }
27732773
27742774 ret = lock_raw_ref (refs , update -> refname , mustexist ,
@@ -2782,7 +2782,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
27822782 strbuf_addf (err , "cannot lock ref '%s': %s" ,
27832783 original_update_refname (update ), reason );
27842784 free (reason );
2785- return ret ;
2785+ goto out ;
27862786 }
27872787
27882788 update -> backend_data = lock ;
@@ -2801,10 +2801,12 @@ static int lock_ref_for_update(struct files_ref_store *refs,
28012801 strbuf_addf (err , "cannot lock ref '%s': "
28022802 "error reading reference" ,
28032803 original_update_refname (update ));
2804- return -1 ;
2804+ ret = -1 ;
2805+ goto out ;
28052806 }
28062807 } else if (check_old_oid (update , & lock -> old_oid , err )) {
2807- return TRANSACTION_GENERIC_ERROR ;
2808+ ret = TRANSACTION_GENERIC_ERROR ;
2809+ goto out ;
28082810 }
28092811 } else {
28102812 /*
@@ -2818,13 +2820,15 @@ static int lock_ref_for_update(struct files_ref_store *refs,
28182820 referent .buf , transaction ,
28192821 affected_refnames , err );
28202822 if (ret )
2821- return ret ;
2823+ goto out ;
28222824 }
28232825 } else {
28242826 struct ref_update * parent_update ;
28252827
2826- if (check_old_oid (update , & lock -> old_oid , err ))
2827- return TRANSACTION_GENERIC_ERROR ;
2828+ if (check_old_oid (update , & lock -> old_oid , err )) {
2829+ ret = TRANSACTION_GENERIC_ERROR ;
2830+ goto out ;
2831+ }
28282832
28292833 /*
28302834 * If this update is happening indirectly because of a
@@ -2861,7 +2865,8 @@ static int lock_ref_for_update(struct files_ref_store *refs,
28612865 "cannot update ref '%s': %s" ,
28622866 update -> refname , write_err );
28632867 free (write_err );
2864- return TRANSACTION_GENERIC_ERROR ;
2868+ ret = TRANSACTION_GENERIC_ERROR ;
2869+ goto out ;
28652870 } else {
28662871 update -> flags |= REF_NEEDS_COMMIT ;
28672872 }
@@ -2875,10 +2880,14 @@ static int lock_ref_for_update(struct files_ref_store *refs,
28752880 if (close_ref (lock )) {
28762881 strbuf_addf (err , "couldn't close '%s.lock'" ,
28772882 update -> refname );
2878- return TRANSACTION_GENERIC_ERROR ;
2883+ ret = TRANSACTION_GENERIC_ERROR ;
2884+ goto out ;
28792885 }
28802886 }
2881- return 0 ;
2887+
2888+ out :
2889+ strbuf_release (& referent );
2890+ return ret ;
28822891}
28832892
28842893/*
0 commit comments