@@ -172,6 +172,11 @@ struct module_list {
172172};
173173#define MODULE_LIST_INIT { 0 }
174174
175+ static void module_list_release (struct module_list * ml )
176+ {
177+ free (ml -> entries );
178+ }
179+
175180static int module_list_compute (int argc , const char * * argv ,
176181 const char * prefix ,
177182 struct pathspec * pathspec ,
@@ -234,7 +239,7 @@ static void module_list_active(struct module_list *list)
234239 active_modules .entries [active_modules .nr ++ ] = ce ;
235240 }
236241
237- free (list -> entries );
242+ module_list_release (list );
238243 * list = active_modules ;
239244}
240245
@@ -407,6 +412,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix)
407412
408413 ret = 0 ;
409414cleanup :
415+ module_list_release (& list );
410416 clear_pathspec (& pathspec );
411417 return ret ;
412418}
@@ -553,6 +559,7 @@ static int module_init(int argc, const char **argv, const char *prefix)
553559
554560 ret = 0 ;
555561cleanup :
562+ module_list_release (& list );
556563 clear_pathspec (& pathspec );
557564 return ret ;
558565}
@@ -730,6 +737,7 @@ static int module_status(int argc, const char **argv, const char *prefix)
730737
731738 ret = 0 ;
732739cleanup :
740+ module_list_release (& list );
733741 clear_pathspec (& pathspec );
734742 return ret ;
735743}
@@ -1302,6 +1310,7 @@ static int module_sync(int argc, const char **argv, const char *prefix)
13021310
13031311 ret = 0 ;
13041312cleanup :
1313+ module_list_release (& list );
13051314 clear_pathspec (& pathspec );
13061315 return ret ;
13071316}
@@ -1454,6 +1463,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix)
14541463
14551464 ret = 0 ;
14561465cleanup :
1466+ module_list_release (& list );
14571467 clear_pathspec (& pathspec );
14581468 return ret ;
14591469}
@@ -1831,6 +1841,12 @@ struct submodule_update_clone {
18311841};
18321842#define SUBMODULE_UPDATE_CLONE_INIT { 0 }
18331843
1844+ static void submodule_update_clone_release (struct submodule_update_clone * suc )
1845+ {
1846+ free (suc -> update_clone );
1847+ free (suc -> failed_clones );
1848+ }
1849+
18341850struct update_data {
18351851 const char * prefix ;
18361852 const char * displaypath ;
@@ -1869,6 +1885,11 @@ struct update_data {
18691885 .max_jobs = 1, \
18701886}
18711887
1888+ static void update_data_release (struct update_data * ud )
1889+ {
1890+ module_list_release (& ud -> list );
1891+ }
1892+
18721893static void next_submodule_warn_missing (struct submodule_update_clone * suc ,
18731894 struct strbuf * out , const char * displaypath )
18741895{
@@ -2554,6 +2575,7 @@ static int update_submodules(struct update_data *update_data)
25542575 }
25552576
25562577cleanup :
2578+ submodule_update_clone_release (& suc );
25572579 string_list_clear (& update_data -> references , 0 );
25582580 return ret ;
25592581}
@@ -2651,6 +2673,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
26512673
26522674 if (module_list_compute (argc , argv , opt .prefix ,
26532675 & pathspec2 , & list ) < 0 ) {
2676+ module_list_release (& list );
26542677 ret = 1 ;
26552678 goto cleanup ;
26562679 }
@@ -2667,10 +2690,12 @@ static int module_update(int argc, const char **argv, const char *prefix)
26672690 info .flags |= OPT_QUIET ;
26682691
26692692 for_each_listed_submodule (& list , init_submodule_cb , & info );
2693+ module_list_release (& list );
26702694 }
26712695
26722696 ret = update_submodules (& opt );
26732697cleanup :
2698+ update_data_release (& opt );
26742699 list_objects_filter_release (& filter_options );
26752700 clear_pathspec (& pathspec );
26762701 clear_pathspec (& pathspec2 );
@@ -2786,6 +2811,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
27862811 ret = 0 ;
27872812cleanup :
27882813 clear_pathspec (& pathspec );
2814+ module_list_release (& list );
27892815 return ret ;
27902816}
27912817
0 commit comments