@@ -727,13 +727,15 @@ static void add_flattened_path(struct strbuf *out, const char *s)
727727 out -> buf [i ] = '_' ;
728728}
729729
730- static char * unique_path (struct strmap * existing_paths ,
730+ static char * unique_path (struct merge_options * opt ,
731731 const char * path ,
732732 const char * branch )
733733{
734+ char * ret = NULL ;
734735 struct strbuf newpath = STRBUF_INIT ;
735736 int suffix = 0 ;
736737 size_t base_len ;
738+ struct strmap * existing_paths = & opt -> priv -> paths ;
737739
738740 strbuf_addf (& newpath , "%s~" , path );
739741 add_flattened_path (& newpath , branch );
@@ -744,7 +746,11 @@ static char *unique_path(struct strmap *existing_paths,
744746 strbuf_addf (& newpath , "_%d" , suffix ++ );
745747 }
746748
747- return strbuf_detach (& newpath , NULL );
749+ /* Track the new path in our memory pool */
750+ ret = mem_pool_alloc (& opt -> priv -> pool , newpath .len + 1 );
751+ memcpy (ret , newpath .buf , newpath .len + 1 );
752+ strbuf_release (& newpath );
753+ return ret ;
748754}
749755
750756/*** Function Grouping: functions related to collect_merge_info() ***/
@@ -3091,12 +3097,11 @@ static int detect_and_process_renames(struct merge_options *opt,
30913097 struct tree * side1 ,
30923098 struct tree * side2 )
30933099{
3094- struct diff_queue_struct combined ;
3100+ struct diff_queue_struct combined = { 0 } ;
30953101 struct rename_info * renames = & opt -> priv -> renames ;
3096- int need_dir_renames , s , clean = 1 ;
3102+ int need_dir_renames , s , i , clean = 1 ;
30973103 unsigned detection_run = 0 ;
30983104
3099- memset (& combined , 0 , sizeof (combined ));
31003105 if (!possible_renames (renames ))
31013106 goto cleanup ;
31023107
@@ -3180,13 +3185,9 @@ static int detect_and_process_renames(struct merge_options *opt,
31803185 free (renames -> pairs [s ].queue );
31813186 DIFF_QUEUE_CLEAR (& renames -> pairs [s ]);
31823187 }
3183- if (combined .nr ) {
3184- int i ;
3185- for (i = 0 ; i < combined .nr ; i ++ )
3186- pool_diff_free_filepair (& opt -> priv -> pool ,
3187- combined .queue [i ]);
3188- free (combined .queue );
3189- }
3188+ for (i = 0 ; i < combined .nr ; i ++ )
3189+ pool_diff_free_filepair (& opt -> priv -> pool , combined .queue [i ]);
3190+ free (combined .queue );
31903191
31913192 return clean ;
31923193}
@@ -3684,7 +3685,7 @@ static void process_entry(struct merge_options *opt,
36843685 */
36853686 df_file_index = (ci -> dirmask & (1 << 1 )) ? 2 : 1 ;
36863687 branch = (df_file_index == 1 ) ? opt -> branch1 : opt -> branch2 ;
3687- path = unique_path (& opt -> priv -> paths , path , branch );
3688+ path = unique_path (opt , path , branch );
36883689 strmap_put (& opt -> priv -> paths , path , new_ci );
36893690
36903691 path_msg (opt , path , 0 ,
@@ -3809,14 +3810,12 @@ static void process_entry(struct merge_options *opt,
38093810 /* Insert entries into opt->priv_paths */
38103811 assert (rename_a || rename_b );
38113812 if (rename_a ) {
3812- a_path = unique_path (& opt -> priv -> paths ,
3813- path , opt -> branch1 );
3813+ a_path = unique_path (opt , path , opt -> branch1 );
38143814 strmap_put (& opt -> priv -> paths , a_path , ci );
38153815 }
38163816
38173817 if (rename_b )
3818- b_path = unique_path (& opt -> priv -> paths ,
3819- path , opt -> branch2 );
3818+ b_path = unique_path (opt , path , opt -> branch2 );
38203819 else
38213820 b_path = path ;
38223821 strmap_put (& opt -> priv -> paths , b_path , new_ci );
@@ -4204,15 +4203,14 @@ static int record_conflicted_index_entries(struct merge_options *opt)
42044203 struct stat st ;
42054204
42064205 if (!lstat (path , & st )) {
4207- char * new_name = unique_path (& opt -> priv -> paths ,
4206+ char * new_name = unique_path (opt ,
42084207 path ,
42094208 "cruft" );
42104209
42114210 path_msg (opt , path , 1 ,
42124211 _ ("Note: %s not up to date and in way of checking out conflicted version; old copy renamed to %s" ),
42134212 path , new_name );
42144213 errs |= rename (path , new_name );
4215- free (new_name );
42164214 }
42174215 errs |= checkout_entry (ce , & state , NULL , NULL );
42184216 }
0 commit comments