Skip to content

Commit 7c94910

Browse files
wenfei-liwenfei-li
andauthored
Fix memory leaks in LCAO part (#1003)
* gint : remove old code in src_lcao * fixed some memory leaks * replace new XXX[1] by nullptr * fix a bug introduced by previous commit Co-authored-by: wenfei-li <[email protected]>
1 parent 7b42f40 commit 7c94910

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+180
-5061
lines changed

source/module_cell/atom_pseudo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Atom_pseudo::Atom_pseudo()
66
pseudo_fn = "not_init";
77
mass = 0.0;
88

9-
for(int is=0;is<4;is++) this->index1_soc[is] = new int[1];
10-
for(int is=0;is<4;is++) this->index2_soc[is] = new int[1];
9+
for(int is=0;is<4;is++) this->index1_soc[is] = nullptr;
10+
for(int is=0;is<4;is++) this->index2_soc[is] = nullptr;
1111

1212
}
1313

source/module_cell/pseudo_nc.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ pseudo_nc::pseudo_nc()
44
{
55
// pseudo_h
66
els = new std::string[1];
7-
lchi = new int[1];
8-
oc = new double[1];
9-
jjj = new double[1];
10-
jchi = new double[1];
11-
nn = new int[1];
7+
lchi = nullptr;
8+
oc = nullptr;
9+
jjj = nullptr;
10+
jchi = nullptr;
11+
nn = nullptr;
1212
has_so = false;
1313
zv = 0;
1414

1515
// pseudo local parts
16-
vloc_at = new double[1];
16+
vloc_at = nullptr;
1717

1818
// pseudo_atom
19-
r = new double[1];
20-
rab = new double[1];
21-
rho_at = new double[1];
22-
rho_atc = new double[1];
19+
r = nullptr;
20+
rab = nullptr;
21+
rho_at = nullptr;
22+
rho_atc = nullptr;
2323

2424
// pseudo_nc
25-
lll = new int[1];
25+
lll = nullptr;
2626
}
2727

2828
pseudo_nc::~pseudo_nc()

source/module_cell/read_pp.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ using namespace std;
1212
Pseudopot_upf::Pseudopot_upf()
1313
{
1414
this->els = new std::string[1];
15-
this->lchi = new int[1];
16-
this->oc = new double[1];
15+
this->lchi = nullptr;
16+
this->oc = nullptr;
1717

18-
this->r = new double[1];
19-
this->rab = new double[1];
20-
this->vloc = new double[1];
18+
this->r = nullptr;
19+
this->rab = nullptr;
20+
this->vloc = nullptr;
2121

22-
this->kkbeta = new int[1];
23-
this->lll = new int[1];
22+
this->kkbeta = nullptr;
23+
this->lll = nullptr;
2424

25-
this->rho_at = new double[1];
26-
this->rho_atc = new double[1];
25+
this->rho_at = nullptr;
26+
this->rho_atc = nullptr;
2727

28-
this->nn = new int[1];//zhengdy-soc
29-
this->jchi = new double[1];
30-
this->jjj = new double[1];
28+
this->nn = nullptr;//zhengdy-soc
29+
this->jchi = nullptr;
30+
this->jjj = nullptr;
3131

3232
functional_error = 0;//xiaohui add 2015-03-24
3333
}

source/module_cell/read_pp_blps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ int Pseudopot_upf::read_pseudo_blps(std::ifstream &ifs)
99
this->nbeta = 0;
1010
delete[] kkbeta;
1111
delete[] lll;
12-
this->kkbeta = new int[1];
13-
this->lll = new int[1];
12+
this->kkbeta = nullptr;
13+
this->lll = nullptr;
1414
this->beta.create(1, 1);
1515
this->dion.create(1, 1);
1616

source/module_cell/read_pp_upf100.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ void Pseudopot_upf::read_pseudo_nl(std::ifstream &ifs)
281281
{
282282
delete[] kkbeta;
283283
delete[] lll;
284-
this->kkbeta = new int[1];
285-
this->lll = new int[1];
284+
this->kkbeta = nullptr;
285+
this->lll = nullptr;
286286
this->beta.create(1, 1);
287287
this->dion.create(1, 1);
288288
return;

source/module_cell/setup_nonlocal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
InfoNonlocal::InfoNonlocal()
1111
{
1212
this->Beta = new Numerical_Nonlocal[1];
13-
this->nproj = new int[1];
13+
this->nproj = nullptr;
1414
this->nprojmax = 0;
1515
this->rcutmax_Beta = 0.0;
1616
}

source/module_cell/unitcell.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ UnitCell::UnitCell()
4444
omega = 0.0;
4545

4646
atom_label = new string[1];
47-
atom_mass = new double[1];
47+
atom_mass = nullptr;
4848
pseudo_fn = new string[1];
4949
}
5050

source/module_deepks/LCAO_deepks.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ LCAO_Deepks::LCAO_Deepks()
3131
{
3232
alpha_index = new ModuleBase::IntArray[1];
3333
inl_index = new ModuleBase::IntArray[1];
34-
inl_l = new int[1];
35-
H_V_delta = new double[1];
36-
H_V_deltaR = new double[1];
34+
inl_l = nullptr;
35+
H_V_delta = nullptr;
36+
H_V_deltaR = nullptr;
3737
}
3838

3939
//Desctructor of the class

source/module_deepks/test/klist_1.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace Test_Deepks
1111
kvec_c = new ModuleBase::Vector3<double>[1];
1212
kvec_d.resize(1);
1313

14-
wk = new double[1];
15-
isk = new int[1];
14+
wk = nullptr;
15+
isk = nullptr;
1616

1717
nkstot = 0;
1818
}

source/module_deepks/test/parallel_orbitals.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace Test_Deepks
55

66
Parallel_Orbitals::Parallel_Orbitals()
77
{
8-
trace_loc_row = new int[1];
9-
trace_loc_col = new int[1];
8+
trace_loc_row = nullptr;
9+
trace_loc_col = nullptr;
1010
}
1111

1212
Parallel_Orbitals::~Parallel_Orbitals()

0 commit comments

Comments
 (0)