From f59e391713ef5b2ac877be00f72f8b0fd3f7a7c5 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 8 Jul 2020 20:10:40 -0400 Subject: [PATCH] avoid leaking empty allocations --- src/atom_vec.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/atom_vec.cpp b/src/atom_vec.cpp index 0aa84d4396..17e22d94b2 100644 --- a/src/atom_vec.cpp +++ b/src/atom_vec.cpp @@ -2495,9 +2495,10 @@ int AtomVec::process_fields(char *str, const char *default_str, Method *method) Atom::PerAtom *peratom = atom->peratom; int nperatom = atom->nperatom; - int *index = new int[nfield]; + int *index; int match; + if (nfield) index = new int[nfield]; for (int i = 0; i < nfield; i++) { const char * field = words[i].c_str(); @@ -2522,7 +2523,8 @@ int AtomVec::process_fields(char *str, const char *default_str, Method *method) error->all(FLERR,fmt::format("Peratom field {} is a default", field)); } - method->index = index; + if (nfield) method->index = index; + else method->index = nullptr; return nfield; }