Fixes for memory leaks in the C interface

This commit is contained in:
Salvatore Filippone
2021-02-02 15:44:12 +01:00
parent 3e6fdd39e4
commit 81fc75a091
11 changed files with 42 additions and 12 deletions
+3 -2
View File
@@ -979,8 +979,9 @@ contains
call psb_close_context(psb_mesg_queue,ctxt)
end if
!if ((ctxt /= mpi_comm_null).and.(ctxt /= mpi_comm_world)) then
if (allocated(ctxt%ctxt)) then
if (ctxt%ctxt /= mpi_comm_world)call mpi_comm_Free(ctxt%ctxt,info)
if (allocated(ctxt%ctxt)) then
!write(0,*) ctxt%ctxt,mpi_comm_world,mpi_comm_null
if ((ctxt%ctxt /= mpi_comm_world).and.(ctxt%ctxt /= mpi_comm_null)) call mpi_comm_Free(ctxt%ctxt,info)
end if
if (close_) call mpi_finalize(info)
+3
View File
@@ -93,6 +93,8 @@ contains
call psb_gefree(xp,descp,info)
res = min(0,info)
deallocate(xp,stat=info)
res = min(0,info)
xh%item = c_null_ptr
return
@@ -264,6 +266,7 @@ contains
call psb_spfree(ap,descp,info)
res = min(0,info)
deallocate(ap,stat=info)
mh%item=c_null_ptr
return
end function psb_c_cspfree
+7 -1
View File
@@ -102,6 +102,9 @@ contains
type(psb_ctxt_type), pointer :: ctxt
ctxt => psb_c2f_ctxt(cctxt)
call psb_exit(ctxt,close=.false.)
deallocate(ctxt,stat=info)
return
end subroutine psb_c_exit_ctxt
@@ -110,9 +113,12 @@ contains
type(psb_c_object_type), value :: cctxt
type(psb_ctxt_type), pointer :: ctxt
integer(psb_ipk_) :: info
ctxt => psb_c2f_ctxt(cctxt)
call psb_exit(ctxt)
deallocate(ctxt,stat=info)
cctxt%item = c_null_ptr
return
end subroutine psb_c_exit
+3
View File
@@ -93,6 +93,8 @@ contains
call psb_gefree(xp,descp,info)
res = min(0,info)
deallocate(xp,stat=info)
res = min(0,info)
xh%item = c_null_ptr
return
@@ -264,6 +266,7 @@ contains
call psb_spfree(ap,descp,info)
res = min(0,info)
deallocate(ap,stat=info)
mh%item=c_null_ptr
return
end function psb_c_dspfree
+3
View File
@@ -93,6 +93,8 @@ contains
call psb_gefree(xp,descp,info)
res = min(0,info)
deallocate(xp,stat=info)
res = min(0,info)
xh%item = c_null_ptr
return
@@ -264,6 +266,7 @@ contains
call psb_spfree(ap,descp,info)
res = min(0,info)
deallocate(ap,stat=info)
mh%item=c_null_ptr
return
end function psb_c_sspfree
+3
View File
@@ -93,6 +93,8 @@ contains
call psb_gefree(xp,descp,info)
res = min(0,info)
deallocate(xp,stat=info)
res = min(0,info)
xh%item = c_null_ptr
return
@@ -264,6 +266,7 @@ contains
call psb_spfree(ap,descp,info)
res = min(0,info)
deallocate(ap,stat=info)
mh%item=c_null_ptr
return
end function psb_c_zspfree
+2 -2
View File
@@ -111,9 +111,9 @@ contains
end if
call psb_precfree(precp, info)
res = min(info,0)
deallocate(precp,stat=info)
ph%item = c_null_ptr
end function psb_c_cprecfree
+2 -2
View File
@@ -111,9 +111,9 @@ contains
end if
call psb_precfree(precp, info)
res = min(info,0)
deallocate(precp,stat=info)
ph%item = c_null_ptr
end function psb_c_dprecfree
+2 -2
View File
@@ -111,9 +111,9 @@ contains
end if
call psb_precfree(precp, info)
res = min(info,0)
deallocate(precp,stat=info)
ph%item = c_null_ptr
end function psb_c_sprecfree
+2 -2
View File
@@ -111,9 +111,9 @@ contains
end if
call psb_precfree(precp, info)
res = min(info,0)
deallocate(precp,stat=info)
ph%item = c_null_ptr
end function psb_c_zprecfree
+12 -1
View File
@@ -385,6 +385,10 @@ int main(int argc, char *argv[])
#endif
/* Clean up memory */
if ((info=psb_c_dprecfree(ph))!=0) {
fprintf(stderr,"From dprecfree: %d\nBailing out\n",info);
psb_c_abort(*cctxt);
}
if ((info=psb_c_dgefree(xh,cdh))!=0) {
fprintf(stderr,"From dgefree: %d\nBailing out\n",info);
psb_c_abort(*cctxt);
@@ -397,6 +401,10 @@ int main(int argc, char *argv[])
fprintf(stderr,"From dgefree: %d\nBailing out\n",info);
psb_c_abort(*cctxt);
}
if ((info=psb_c_dspfree(ah,cdh))!=0) {
fprintf(stderr,"From dspfree: %d\nBailing out\n",info);
psb_c_abort(*cctxt);
}
if ((info=psb_c_cdfree(cdh))!=0) {
fprintf(stderr,"From cdfree: %d\nBailing out\n",info);
@@ -408,12 +416,15 @@ int main(int argc, char *argv[])
free(ph);
free(xh);
free(bh);
free(rh);
free(ah);
free(cdh);
/* further cleanup */
free(vl);
//if (iam == 0) fprintf(stderr,"program completed successfully\n");
psb_c_barrier(*cctxt);
psb_c_exit(*cctxt);
free(cctxt);
}