@@ -3317,15 +3317,20 @@ static int perf_sched__map(struct perf_sched *sched)
33173317
33183318static int perf_sched__replay (struct perf_sched * sched )
33193319{
3320+ int ret ;
33203321 unsigned long i ;
33213322
3323+ mutex_init (& sched -> start_work_mutex );
3324+ mutex_init (& sched -> work_done_wait_mutex );
3325+
33223326 calibrate_run_measurement_overhead (sched );
33233327 calibrate_sleep_measurement_overhead (sched );
33243328
33253329 test_calibrations (sched );
33263330
3327- if (perf_sched__read_events (sched ))
3328- return -1 ;
3331+ ret = perf_sched__read_events (sched );
3332+ if (ret )
3333+ goto out_mutex_destroy ;
33293334
33303335 printf ("nr_run_events: %ld\n" , sched -> nr_run_events );
33313336 printf ("nr_sleep_events: %ld\n" , sched -> nr_sleep_events );
@@ -3350,7 +3355,11 @@ static int perf_sched__replay(struct perf_sched *sched)
33503355
33513356 sched -> thread_funcs_exit = true;
33523357 destroy_tasks (sched );
3353- return 0 ;
3358+
3359+ out_mutex_destroy :
3360+ mutex_destroy (& sched -> start_work_mutex );
3361+ mutex_destroy (& sched -> work_done_wait_mutex );
3362+ return ret ;
33543363}
33553364
33563365static void setup_sorting (struct perf_sched * sched , const struct option * options ,
@@ -3588,8 +3597,6 @@ int cmd_sched(int argc, const char **argv)
35883597 unsigned int i ;
35893598 int ret = 0 ;
35903599
3591- mutex_init (& sched .start_work_mutex );
3592- mutex_init (& sched .work_done_wait_mutex );
35933600 sched .curr_thread = calloc (MAX_CPUS , sizeof (* sched .curr_thread ));
35943601 if (!sched .curr_thread ) {
35953602 ret = - ENOMEM ;
@@ -3677,8 +3684,6 @@ int cmd_sched(int argc, const char **argv)
36773684 free (sched .curr_pid );
36783685 free (sched .cpu_last_switched );
36793686 free (sched .curr_thread );
3680- mutex_destroy (& sched .start_work_mutex );
3681- mutex_destroy (& sched .work_done_wait_mutex );
36823687
36833688 return ret ;
36843689}
0 commit comments