From 095ca76b5bb652b700d191187c8f4b63b07cf077 Mon Sep 17 00:00:00 2001
From: Axel Kohlmeyer <akohlmey@gmail.com>
Date: Sat, 5 May 2018 11:44:21 -0400
Subject: [PATCH] plug memory leaks in USER-BOCS

---
 src/USER-BOCS/compute_pressure_bocs.cpp | 7 +++++--
 src/USER-BOCS/fix_bocs.cpp              | 3 +++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/USER-BOCS/compute_pressure_bocs.cpp b/src/USER-BOCS/compute_pressure_bocs.cpp
index 29397f1fab..fc24efab4c 100644
--- a/src/USER-BOCS/compute_pressure_bocs.cpp
+++ b/src/USER-BOCS/compute_pressure_bocs.cpp
@@ -52,6 +52,7 @@ ComputePressureBocs::ComputePressureBocs(LAMMPS *lmp, int narg, char **arg) :
   timeflag = 1;
 
   p_match_flag = 0;
+  phi_coeff = NULL;
 
   // store temperature ID used by pressure computation
   // insure it is valid for temperature computation
@@ -119,6 +120,7 @@ ComputePressureBocs::~ComputePressureBocs()
   delete [] id_temp;
   delete [] vector;
   delete [] vptr;
+  if (phi_coeff) free(phi_coeff);
 }
 
 /* ---------------------------------------------------------------------- */
@@ -263,6 +265,7 @@ void ComputePressureBocs::send_cg_info(int basis_type, int sent_N_basis,
   p_match_flag = 1;
 
   N_basis = sent_N_basis;
+  if (phi_coeff) free(phi_coeff);
   phi_coeff = ((double *) calloc(N_basis, sizeof(double)) );
   for (int i=0; i<N_basis; i++) { phi_coeff[i] = sent_phi_coeff[i]; }
 
@@ -327,10 +330,10 @@ double ComputePressureBocs::compute_scalar()
     if (keflag)
       scalar = (temperature->dof * boltz * t +
                 virial[0] + virial[1] + virial[2]) / 3.0 *
-                inv_volume * nktv2p + (correction);  correction
+                inv_volume * nktv2p + (correction);
     else
       scalar = (virial[0] + virial[1] + virial[2]) / 3.0 *
-               inv_volume * nktv2p + (correction);  correction
+               inv_volume * nktv2p + (correction);
   } else {
     if (p_match_flag)
     {
diff --git a/src/USER-BOCS/fix_bocs.cpp b/src/USER-BOCS/fix_bocs.cpp
index ba74d6be1f..8f1b73b780 100644
--- a/src/USER-BOCS/fix_bocs.cpp
+++ b/src/USER-BOCS/fix_bocs.cpp
@@ -107,6 +107,8 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) :
   id_temp = NULL;
   id_press = NULL;
 
+  p_match_coeffs = NULL;
+
   // turn on tilt factor scaling, whenever applicable
 
   dimension = domain->dimension;
@@ -463,6 +465,7 @@ FixBocs::~FixBocs()
       delete [] etap_mass;
     }
   }
+  if (p_match_coeffs) free(p_match_coeffs);
 }
 
 /* ---------------------------------------------------------------------- */
-- 
GitLab