avoid a case of mixing malloc()/free() with new/delete

This commit is contained in:
Axel Kohlmeyer 2019-06-10 18:22:04 -04:00
parent 72b295d7f4
commit 3e2f3a8058
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
1 changed files with 4 additions and 4 deletions

View File

@ -288,11 +288,11 @@ void Variable::set(int narg, char **arg)
int maxcopy = strlen(arg[2]) + 1;
int maxwork = maxcopy;
char *scopy = new char[maxcopy];
char *work = new char[maxwork];
char *scopy = (char *) memory->smalloc(maxcopy,"var:string/copy");
char *work = (char *) memory->smalloc(maxwork,"var:string/work");
strcpy(scopy,arg[2]);
input->substitute(scopy,work,maxcopy,maxwork,1);
delete [] work;
memory->sfree(work);
int ivar = find(arg[0]);
if (ivar >= 0) {
@ -310,7 +310,7 @@ void Variable::set(int narg, char **arg)
data[nvar] = new char*[num[nvar]];
copy(1,&scopy,data[nvar]);
}
delete [] scopy;
memory->sfree(scopy);
// GETENV
// remove pre-existing var if also style GETENV (allows it to be reset)