Skip to content

Commit

Permalink
chore: remove defensive checks for nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
hellkite500 committed Jul 10, 2024
1 parent ca3e132 commit a004431
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions src/bmi_lgar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ string verbosity="none";
*
*/
BmiLGAR::~BmiLGAR(){
if( giuh_ordinates != nullptr ) delete [] giuh_ordinates;
if( giuh_runoff_queue != nullptr ) delete [] giuh_runoff_queue;
delete [] giuh_ordinates;
delete [] giuh_runoff_queue;
}

/* The `head` pointer stores the address in memory of the first member of the linked list containing
Expand Down Expand Up @@ -62,10 +62,9 @@ Initialize (std::string config_file)
*
*/
void BmiLGAR::realloc_soil(){
if(state->lgar_bmi_params.soil_depth_wetting_fronts != nullptr)
delete [] state->lgar_bmi_params.soil_depth_wetting_fronts;
if(state->lgar_bmi_params.soil_moisture_wetting_fronts != nullptr)
delete [] state->lgar_bmi_params.soil_moisture_wetting_fronts;

delete [] state->lgar_bmi_params.soil_depth_wetting_fronts;
delete [] state->lgar_bmi_params.soil_moisture_wetting_fronts;

state->lgar_bmi_params.soil_depth_wetting_fronts = new double[state->lgar_bmi_params.num_wetting_fronts];
state->lgar_bmi_params.soil_moisture_wetting_fronts = new double[state->lgar_bmi_params.num_wetting_fronts];
Expand Down Expand Up @@ -631,30 +630,30 @@ void BmiLGAR::
Finalize()
{
global_mass_balance();
if( state->head != NULL ) listDelete(state->head);
if( state->state_previous != NULL ) listDelete(state->state_previous);

if( state->soil_properties != nullptr ) delete [] state->soil_properties;

if( state->lgar_bmi_params.soil_depth_wetting_fronts != nullptr ) delete [] state->lgar_bmi_params.soil_depth_wetting_fronts;
if( state->lgar_bmi_params.soil_moisture_wetting_fronts != nullptr) delete [] state->lgar_bmi_params.soil_moisture_wetting_fronts;

if( state->lgar_bmi_params.soil_temperature != nullptr ) delete [] state->lgar_bmi_params.soil_temperature;
if( state->lgar_bmi_params.soil_temperature_z != nullptr) delete [] state->lgar_bmi_params.soil_temperature_z;
if( state->lgar_bmi_params.layer_soil_type != nullptr ) delete [] state->lgar_bmi_params.layer_soil_type;

if( state->lgar_calib_params.theta_e != nullptr ) delete [] state->lgar_calib_params.theta_e;
if( state->lgar_calib_params.theta_r != nullptr ) delete [] state->lgar_calib_params.theta_r;
if( state->lgar_calib_params.vg_n != nullptr ) delete [] state->lgar_calib_params.vg_n;
if( state->lgar_calib_params.vg_alpha != nullptr ) delete [] state->lgar_calib_params.vg_alpha;
if( state->lgar_calib_params.Ksat != nullptr ) delete [] state->lgar_calib_params.Ksat;

if( state->lgar_bmi_params.layer_thickness_cm != nullptr ) delete [] state->lgar_bmi_params.layer_thickness_cm;
if( state->lgar_bmi_params.cum_layer_thickness_cm != nullptr ) delete [] state->lgar_bmi_params.cum_layer_thickness_cm;
if( state->lgar_bmi_params.giuh_ordinates != nullptr ) delete [] state->lgar_bmi_params.giuh_ordinates;
if( state->lgar_bmi_params.frozen_factor != nullptr ) delete [] state->lgar_bmi_params.frozen_factor;
if( state->lgar_bmi_input_params != nullptr ) delete state->lgar_bmi_input_params;
if( state != nullptr ) delete state;
listDelete(state->head);
listDelete(state->state_previous);

delete [] state->soil_properties;

delete [] state->lgar_bmi_params.soil_depth_wetting_fronts;
delete [] state->lgar_bmi_params.soil_moisture_wetting_fronts;

delete [] state->lgar_bmi_params.soil_temperature;
delete [] state->lgar_bmi_params.soil_temperature_z;
delete [] state->lgar_bmi_params.layer_soil_type;

delete [] state->lgar_calib_params.theta_e;
delete [] state->lgar_calib_params.theta_r;
delete [] state->lgar_calib_params.vg_n;
delete [] state->lgar_calib_params.vg_alpha;
delete [] state->lgar_calib_params.Ksat;

delete [] state->lgar_bmi_params.layer_thickness_cm;
delete [] state->lgar_bmi_params.cum_layer_thickness_cm;
delete [] state->lgar_bmi_params.giuh_ordinates;
delete [] state->lgar_bmi_params.frozen_factor;
delete state->lgar_bmi_input_params;
delete state;
}


Expand Down

0 comments on commit a004431

Please sign in to comment.