Avoid string duplication and remove memory leak

This commit is contained in:
Richard Berger
2020-09-25 13:44:28 -04:00
parent 28812b1ea7
commit 26ad664079
2 changed files with 28 additions and 3 deletions

View File

@ -1234,12 +1234,11 @@ void Input::shell()
} else if (strcmp(arg[0],"putenv") == 0) {
if (narg < 2) error->all(FLERR,"Illegal shell putenv command");
for (int i = 1; i < narg; i++) {
char *ptr = strdup(arg[i]);
rv = 0;
#ifdef _WIN32
if (ptr != nullptr) rv = _putenv(ptr);
if (arg[i]) rv = _putenv(arg[i]);
#else
if (ptr != nullptr) rv = putenv(ptr);
if (arg[i]) rv = putenv(arg[i]);
#endif
rv = (rv < 0) ? errno : 0;
MPI_Reduce(&rv,&err,1,MPI_INT,MPI_MAX,0,world);