Skip to content

Commit a9f10b8

Browse files
committed
< fix >
fix the memory release bug in unit test (test2-2.cpp and test2-3.cpp).
1 parent dfdf315 commit a9f10b8

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

source/module_pw/unittest/test2-2.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ int main(int argc,char **argv)
5555
GT = latvec.Inverse();
5656
G = GT.Transpose();
5757
GGT = G * GT;
58-
58+
complex<double> *tmp = NULL;
5959
if(myrank == 0)
6060
{
61-
complex<double> *tmp = new complex<double> [nx*ny*nz];
61+
tmp = new complex<double> [nx*ny*nz];
6262
for(int ix = 0 ; ix < nx ; ++ix)
6363
{
6464
for(int iy = 0 ; iy < ny ; ++iy)
@@ -80,7 +80,8 @@ int main(int argc,char **argv)
8080
}
8181
}
8282
fftw_plan pp = fftw_plan_dft_3d(nx,ny,nz,(fftw_complex *) tmp, (fftw_complex *) tmp, FFTW_BACKWARD, FFTW_ESTIMATE);
83-
fftw_execute(pp);
83+
fftw_execute(pp);
84+
fftw_destroy_plan(pp);
8485

8586
//output
8687
cout << "reference\n";
@@ -153,6 +154,9 @@ int main(int argc,char **argv)
153154
}
154155

155156

156-
MPI_Barrier(MPI_COMM_WORLD);
157+
MPI_Barrier(MPI_COMM_WORLD);
158+
delete [] rhog;
159+
delete [] rhor;
160+
if(tmp!=NULL) delete []tmp;
157161
return 0;
158162
}

source/module_pw/unittest/test2-3.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ int main(int argc,char **argv)
5555
GT = latvec.Inverse();
5656
G = GT.Transpose();
5757
GGT = G * GT;
58-
58+
complex<double> *tmp = NULL;
5959
if(myrank == 0)
6060
{
61-
complex<double> *tmp = new complex<double> [nx*ny*nz];
61+
tmp = new complex<double> [nx*ny*nz];
6262
for(int ix = 0 ; ix < nx ; ++ix)
6363
{
6464
for(int iy = 0 ; iy < ny ; ++iy)
@@ -81,7 +81,8 @@ int main(int argc,char **argv)
8181
}
8282
}
8383
fftw_plan pp = fftw_plan_dft_3d(nx,ny,nz,(fftw_complex *) tmp, (fftw_complex *) tmp, FFTW_BACKWARD, FFTW_ESTIMATE);
84-
fftw_execute(pp);
84+
fftw_execute(pp);
85+
fftw_destroy_plan(pp);
8586

8687
//output
8788
cout << "reference\n";
@@ -152,6 +153,8 @@ int main(int argc,char **argv)
152153
}
153154

154155
MPI_Barrier(MPI_COMM_WORLD);
155-
156+
delete [] rhog;
157+
delete [] rhor;
158+
if(tmp!=NULL) delete []tmp;
156159
return 0;
157160
}

0 commit comments

Comments
 (0)