@@ -3329,15 +3329,20 @@ static int perf_sched__map(struct perf_sched *sched)
33293329
33303330static  int  perf_sched__replay (struct  perf_sched  * sched )
33313331{
3332+ 	int  ret ;
33323333	unsigned long  i ;
33333334
3335+ 	mutex_init (& sched -> start_work_mutex );
3336+ 	mutex_init (& sched -> work_done_wait_mutex );
3337+ 
33343338	calibrate_run_measurement_overhead (sched );
33353339	calibrate_sleep_measurement_overhead (sched );
33363340
33373341	test_calibrations (sched );
33383342
3339- 	if  (perf_sched__read_events (sched ))
3340- 		return  -1 ;
3343+ 	ret  =  perf_sched__read_events (sched );
3344+ 	if  (ret )
3345+ 		goto out_mutex_destroy ;
33413346
33423347	printf ("nr_run_events:        %ld\n" , sched -> nr_run_events );
33433348	printf ("nr_sleep_events:      %ld\n" , sched -> nr_sleep_events );
@@ -3362,7 +3367,11 @@ static int perf_sched__replay(struct perf_sched *sched)
33623367
33633368	sched -> thread_funcs_exit  =  true;
33643369	destroy_tasks (sched );
3365- 	return  0 ;
3370+ 
3371+ out_mutex_destroy :
3372+ 	mutex_destroy (& sched -> start_work_mutex );
3373+ 	mutex_destroy (& sched -> work_done_wait_mutex );
3374+ 	return  ret ;
33663375}
33673376
33683377static  void  setup_sorting (struct  perf_sched  * sched , const  struct  option  * options ,
@@ -3600,8 +3609,6 @@ int cmd_sched(int argc, const char **argv)
36003609	unsigned int   i ;
36013610	int  ret  =  0 ;
36023611
3603- 	mutex_init (& sched .start_work_mutex );
3604- 	mutex_init (& sched .work_done_wait_mutex );
36053612	sched .curr_thread  =  calloc (MAX_CPUS , sizeof (* sched .curr_thread ));
36063613	if  (!sched .curr_thread ) {
36073614		ret  =  - ENOMEM ;
@@ -3689,8 +3696,6 @@ int cmd_sched(int argc, const char **argv)
36893696	free (sched .curr_pid );
36903697	free (sched .cpu_last_switched );
36913698	free (sched .curr_thread );
3692- 	mutex_destroy (& sched .start_work_mutex );
3693- 	mutex_destroy (& sched .work_done_wait_mutex );
36943699
36953700	return  ret ;
36963701}
0 commit comments