Skip to content

Commit

Permalink
Fixed minor memory leak issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ttadano committed Nov 25, 2017
1 parent 007aadd commit 4d3454d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 14 deletions.
35 changes: 24 additions & 11 deletions alm/constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,33 @@ using namespace ALM_NS;

Constraint::Constraint(ALM *alm) : Pointers(alm)
{
const_symmetry = nullptr;
const_fix = nullptr;
const_relate = nullptr;
index_bimap = nullptr;
const_mat = nullptr;
const_rhs = nullptr;
}

Constraint::~Constraint()
{
if (exist_constraint && alm->mode == "fitting") {

if (const_symmetry) {
memory->deallocate(const_symmetry);

if (constraint_algebraic) {
memory->deallocate(const_fix);
memory->deallocate(const_relate);
memory->deallocate(index_bimap);
} else {
memory->deallocate(const_mat);
memory->deallocate(const_rhs);
}
}
if (const_fix) {
memory->deallocate(const_fix);
}
if (const_relate) {
memory->deallocate(const_relate);
}
if (index_bimap) {
memory->deallocate(index_bimap);
}
if (const_mat) {
memory->deallocate(const_mat);
}
if (const_rhs) {
memory->deallocate(const_rhs);
}
}

Expand Down Expand Up @@ -540,6 +551,8 @@ void Constraint::get_mapping_constraint(const int nmax,
}

memory->deallocate(has_constraint);
memory->deallocate(fix_forceconstant);
memory->deallocate(file_forceconstant);
}

void Constraint::generate_symmetry_constraint_in_cartesian(std::vector<ConstraintClass> *const_out)
Expand Down
6 changes: 6 additions & 0 deletions alm/interaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ using namespace ALM_NS;

Interaction::Interaction(ALM *alm) : Pointers(alm)
{
rcs = nullptr;
}

Interaction::~Interaction()
Expand All @@ -43,6 +44,9 @@ Interaction::~Interaction()
memory->deallocate(interaction_pair);
memory->deallocate(mindist_cluster);
memory->deallocate(distall);
if (rcs) {
memory->deallocate(rcs);
}
}

void Interaction::init()
Expand Down Expand Up @@ -193,6 +197,8 @@ void Interaction::generate_coordinate_of_periodic_images(const unsigned int nat,
for (ja = -1; ja <= 1; ++ja) {
for (ka = -1; ka <= 1; ++ka) {

if (ia == 0 && ja == 0 && ka == 0) continue;

++icell;

// When periodic flag is zero along an axis,
Expand Down
27 changes: 24 additions & 3 deletions alm/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,34 @@ using namespace ALM_NS;

System::System(ALM *alm): Pointers(alm)
{
kdname = nullptr;
kd = nullptr;
xcoord = nullptr;
magmom = nullptr;
x_cartesian = nullptr;
atomlist_class = nullptr;
}

System::~System()
{
memory->deallocate(x_cartesian);
memory->deallocate(atomlist_class);
memory->deallocate(magmom);
if (kdname) {
memory->deallocate(kdname);
}
if (kd) {
memory->deallocate(kd);
}
if (xcoord) {
memory->deallocate(xcoord);
}
if (magmom) {
memory->deallocate(magmom);
}
if (x_cartesian) {
memory->deallocate(x_cartesian);
}
if (atomlist_class) {
memory->deallocate(atomlist_class);
}
}

void System::init()
Expand Down

0 comments on commit 4d3454d

Please sign in to comment.