Skip to content

Commit 93791bb

Browse files
authored
Merge pull request #999 from Qianruipku/develop
fix: memory leak
2 parents 2f9d2df + dc40bad commit 93791bb

File tree

8 files changed

+20
-19
lines changed

8 files changed

+20
-19
lines changed

source/driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void Driver::atomic_world(void)
9393
// lcao: linear combination of atomic orbitals
9494
//--------------------------------------------------
9595
string use_ensol;
96-
ModuleESolver::ESolver *p_esolver;
96+
ModuleESolver::ESolver *p_esolver = nullptr;
9797
if(GlobalV::BASIS_TYPE=="pw" || GlobalV::BASIS_TYPE=="lcao_in_pw")
9898
{
9999
if(GlobalV::CALCULATION.substr(0,3) == "sto") use_ensol = "sdft_pw";

source/module_esolver/esolver.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ namespace ModuleESolver
4545

4646
void clean_esolver(ESolver*& pesolver)
4747
{
48-
if (pesolver != NULL)
49-
{
50-
delete pesolver;
51-
}
48+
delete pesolver;
5249
}
5350

5451
}

source/module_esolver/esolver_fp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace ModuleESolver
1414
}
1515
ESolver_FP::~ESolver_FP()
1616
{
17-
if(pw_rho!=NULL) delete pw_rho;
17+
delete pw_rho;
1818
}
1919
void ESolver_FP::Init(Input& inp, UnitCell_pseudo& cell)
2020
{

source/module_esolver/esolver_ks.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ namespace ModuleESolver
3636
tmp->setbxyz(INPUT.bx,INPUT.by,INPUT.bz);
3737
}
3838

39+
ESolver_KS::~ESolver_KS()
40+
{
41+
delete this->pw_wfc;
42+
delete this->pelec;
43+
delete this->phami;
44+
delete this->phsol;
45+
}
46+
3947
void ESolver_KS::Init(Input& inp, UnitCell_pseudo& ucell)
4048
{
4149
ESolver_FP::Init(inp,ucell);

source/module_esolver/esolver_ks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace ModuleESolver
1616
{
1717
public:
1818
ESolver_KS();
19+
virtual ~ESolver_KS();
1920
// HSolver* phsol;
2021
double diag_ethr; // diag threshold
2122
double scf_thr; // scf threshold

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,6 @@ namespace ModuleESolver
4848
}
4949
ESolver_KS_PW::~ESolver_KS_PW()
5050
{
51-
if(this->pelec!=nullptr)
52-
{
53-
delete this->pelec;
54-
}
55-
if(this->phami!=nullptr)
56-
{
57-
delete this->phami;
58-
}
59-
if(this->phsol!=nullptr)
60-
{
61-
delete this->phsol;
62-
}
6351
}
6452

6553
void ESolver_KS_PW::Init(Input& inp, UnitCell_pseudo& ucell)

source/module_pw/pw_basis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void PW_Basis::getfftixy2is(int * fftixy2is)
191191
//Note: please assert when is1 >= is2, fftixy2is[is1] >= fftixy2is[is2]!
192192
for(int ixy = 0 ; ixy < this->fftnxy ; ++ixy) fftixy2is[ixy] = -1;
193193
int ixy = 0;
194-
for(int is = 0; is < this->nst+1; ++is)
194+
for(int is = 0; is < this->nst; ++is)
195195
{
196196
for(; ixy < this->fftnxy ; ++ixy)
197197
{

source/module_pw/test/test1-1-1.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ TEST_F(PWTEST,test1_1_1)
216216
{
217217
EXPECT_NEAR(pwtest.gg[ig], pwtest.gg_uniq[pwtest.ig2igg[ig]],1e-8);
218218
}
219+
int * irindex = new int [pwtest.fftnxy];
220+
pwtest.getfftixy2is(irindex);
221+
for(int is = 0 ; is < pwtest.nst ;++is)
222+
{
223+
EXPECT_EQ(irindex[pwtest.is2fftixy[is]],is);
224+
}
225+
delete[] irindex;
219226

220227

221228
}

0 commit comments

Comments
 (0)