Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leaks detected with valgrind #37

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/base/target_cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@ xdd_target_thread_cleanup(target_data_t *tdp) {
perror("reason");
}
}
/* Free target seek list created in xint_target_init */
free(tdp->td_seekhdr.seeks);
/* Free target offset table created in xint_target_init */
tot_destroy(tdp->td_totp);
/* Free filename malloced in xdd_target_name */
free(tdp->td_target_full_pathname);

} // End of xdd_target_thread_cleanup()
3 changes: 3 additions & 0 deletions src/base/target_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ xint_target_init_start_worker_threads(target_data_t *tdp) {
perror("Reason");
return(-1);
}

pthread_detach(wdp->wd_thread);

/* Wait for the previous thread to initialize before creating the next one */
xdd_barrier(&tdp->td_target_worker_thread_init_barrier,&tdp->td_occupant,1);
if (xgp->global_options & GO_REALLYVERBOSE) {
Expand Down
37 changes: 37 additions & 0 deletions src/base/xint_plan.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ int xint_plan_start_targets(xdd_plan_t *planp) {
perror("Reason");
return(-1);
}

pthread_detach(tdp->td_thread);

// Wait for the Target Thread to complete initialization and then create the next one
xdd_barrier(&planp->main_general_init_barrier,&barrier_occupant,1);

Expand Down Expand Up @@ -194,6 +197,9 @@ void xint_plan_start_results_manager(xdd_plan_t *planp) {
xdd_destroy_all_barriers(planp);
exit(XDD_RETURN_VALUE_INIT_FAILURE);
}

pthread_detach(planp->Results_Thread);

// Enter this barrier and wait for the results monitor to initialize
xdd_barrier(&planp->main_general_init_barrier,&barrier_occupant,1);

Expand Down Expand Up @@ -265,6 +271,37 @@ void xint_plan_start_interactive(xdd_plan_t *planp) {

} // End of xdd_start_interactive()

/* Will free all malloced objects associated with xdd_plan_t */
void xint_plan_cleanup(xdd_plan_t *planp) {

target_data_t *tdp;
worker_data_t *wdp;
worker_data_t *temp;

for (int32_t i = 0; i < planp->number_of_targets; i++) {
if (planp->target_datap[i] != 0) {

tdp = planp->target_datap[i];
wdp = tdp->td_next_wdp;

while (wdp) {
temp = wdp;
wdp = wdp->wd_next_wdp;
free(temp);
}

free(tdp);

if (planp->target_average_resultsp[i] != 0)
free(planp->target_average_resultsp[i]);
}
}

free(xgp->id);
free(xgp);
free(planp);
}// End of xint_plan_cleaup()

/*
* Plan finalize
*/
Expand Down
10 changes: 6 additions & 4 deletions src/client/results_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ xdd_results_manager(void *data) {
status = xdd_results_manager_init(planp);
if (status < 0) {
fprintf(stderr,"%s: xdd_results_manager: ERROR: Exiting due to previous initialization failure.\n",xgp->progname);
return(0);
goto out;
}

// Enter this barrier to release main indicating that results manager has initialized
xdd_init_barrier_occupant(&barrier_occupant, "RESULTS_MANAGER", (XDD_OCCUPANT_TYPE_SUPPORT), NULL);
xdd_barrier(&planp->main_general_init_barrier,&barrier_occupant,0);

if (xgp->global_options & GO_DRYRUN) {
return(0);
goto out;
}

// This is the loop that runs continuously throughout the xdd run
Expand All @@ -84,7 +84,7 @@ xdd_results_manager(void *data) {
xdd_process_run_results(planp);
// Release all the Target Threads so that they can do their cleanup and exit
xdd_barrier(&planp->results_targets_display_barrier,&barrier_occupant,1);
return(0);
goto out;
}

// Display the header and units line if necessary
Expand All @@ -106,7 +106,7 @@ xdd_results_manager(void *data) {

// Enter the FINAL barrier to tell XDD MAIN that everything is complete
xdd_barrier(&planp->main_results_final_barrier,&barrier_occupant,0);
return(0);
goto out;
} else {
xdd_process_pass_results(planp);
planp->current_pass_number++;
Expand Down Expand Up @@ -134,6 +134,8 @@ xdd_results_manager(void *data) {
xdd_barrier(&planp->results_targets_display_barrier,&barrier_occupant,1);

} // End of main WHILE loop for the results_manager()
out:
free(tmprp);
return(0);
} // End of xdd_results_manager()

Expand Down
1 change: 1 addition & 0 deletions src/client/xdd.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ DFLOW("\n----------------------All targets should start now---------------------
xdd_destroy_all_barriers(planp);

/* Time to leave... sigh */
xint_plan_cleanup(planp);
return(return_value);
} /* end of main() */

Expand Down
2 changes: 2 additions & 0 deletions src/common/xint_plan.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ void xint_plan_start_restart_monitor(xdd_plan_t* planp);

void xint_plan_start_interactive(xdd_plan_t* planp);

void xint_plan_cleanup(xdd_plan_t* planp);

#endif
/*
* Local variables:
Expand Down
Loading