From 59fb8a683577b032593326eea08e359edcefd3f3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 15 Jun 2024 14:08:14 -0400 Subject: [PATCH] avoid segfault trying to delete non-copied style --- src/update.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/update.cpp b/src/update.cpp index 13ff7c872a..c9e57f9621 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -328,7 +328,8 @@ void Update::create_integrate(int narg, char **arg, int trysuffix) delete[] integrate_style; delete integrate; - integrate_style = nullptr; + // temporarily assign the style name without suffix (for error messages during creation) + integrate_style = utils::strdup(arg[0]); integrate = nullptr; int sflag; @@ -349,6 +350,7 @@ void Update::create_integrate(int narg, char **arg, int trysuffix) else if ((sflag == 3) && lmp->non_pair_suffix()) estyle += lmp->non_pair_suffix(); } + delete[] integrate_style; integrate_style = utils::strdup(estyle); } @@ -398,11 +400,10 @@ void Update::create_minimize(int narg, char **arg, int trysuffix) delete[] minimize_style; delete minimize; - minimize_style = nullptr; + // temporarily assign the style name without suffix (for error messages during creation) + minimize_style = utils::strdup(arg[0]); minimize = nullptr; - // temporarily assign the style name without suffix (for error messages during creation) - minimize_style = arg[0]; int sflag; new_minimize(arg[0], narg - 1, &arg[1], trysuffix, sflag); @@ -417,6 +418,7 @@ void Update::create_minimize(int narg, char **arg, int trysuffix) else if ((sflag == 3) && lmp->non_pair_suffix()) estyle += lmp->non_pair_suffix(); } + delete[] minimize_style; minimize_style = utils::strdup(estyle); }