must initialize deleted pointers to null since the following commands may fail

This commit is contained in:
Axel Kohlmeyer
2023-10-21 06:28:14 -04:00
parent c90f874a0d
commit 723dc17d80
2 changed files with 14 additions and 0 deletions

View File

@ -332,6 +332,8 @@ void Force::create_bond(const std::string &style, int trysuffix)
{
delete[] bond_style;
if (bond) delete bond;
bond_style = nullptr;
bond = nullptr;
int sflag;
bond = new_bond(style, trysuffix, sflag);
@ -400,6 +402,8 @@ void Force::create_angle(const std::string &style, int trysuffix)
{
delete[] angle_style;
if (angle) delete angle;
angle_style = nullptr;
angle = nullptr;
int sflag;
angle = new_angle(style, trysuffix, sflag);
@ -468,6 +472,8 @@ void Force::create_dihedral(const std::string &style, int trysuffix)
{
delete[] dihedral_style;
if (dihedral) delete dihedral;
dihedral_style = nullptr;
dihedral = nullptr;
int sflag;
dihedral = new_dihedral(style, trysuffix, sflag);
@ -536,6 +542,8 @@ void Force::create_improper(const std::string &style, int trysuffix)
{
delete[] improper_style;
if (improper) delete improper;
improper_style = nullptr;
improper = nullptr;
int sflag;
improper = new_improper(style, trysuffix, sflag);
@ -604,6 +612,8 @@ void Force::create_kspace(const std::string &style, int trysuffix)
{
delete[] kspace_style;
if (kspace) delete kspace;
kspace_style = nullptr;
kspace = nullptr;
int sflag;
kspace = new_kspace(style, trysuffix, sflag);

View File

@ -332,6 +332,8 @@ void Update::create_integrate(int narg, char **arg, int trysuffix)
delete[] integrate_style;
delete integrate;
integrate_style = nullptr;
integrate = nullptr;
int sflag;
@ -400,6 +402,8 @@ void Update::create_minimize(int narg, char **arg, int trysuffix)
delete[] minimize_style;
delete minimize;
minimize_style = nullptr;
minimize = nullptr;
// temporarily assign the style name without suffix (for error messages during creation)
minimize_style = arg[0];