Fixes for memory leaks in the C interface

newG2L
Salvatore Filippone 4 years ago
parent 3e6fdd39e4
commit 81fc75a091

@ -979,8 +979,9 @@ contains
call psb_close_context(psb_mesg_queue,ctxt) call psb_close_context(psb_mesg_queue,ctxt)
end if end if
!if ((ctxt /= mpi_comm_null).and.(ctxt /= mpi_comm_world)) then !if ((ctxt /= mpi_comm_null).and.(ctxt /= mpi_comm_world)) then
if (allocated(ctxt%ctxt)) then if (allocated(ctxt%ctxt)) then
if (ctxt%ctxt /= mpi_comm_world)call mpi_comm_Free(ctxt%ctxt,info) !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 end if
if (close_) call mpi_finalize(info) if (close_) call mpi_finalize(info)

@ -93,6 +93,8 @@ contains
call psb_gefree(xp,descp,info) call psb_gefree(xp,descp,info)
res = min(0,info) res = min(0,info)
deallocate(xp,stat=info)
res = min(0,info)
xh%item = c_null_ptr xh%item = c_null_ptr
return return
@ -264,6 +266,7 @@ contains
call psb_spfree(ap,descp,info) call psb_spfree(ap,descp,info)
res = min(0,info) res = min(0,info)
deallocate(ap,stat=info)
mh%item=c_null_ptr mh%item=c_null_ptr
return return
end function psb_c_cspfree end function psb_c_cspfree

@ -102,6 +102,9 @@ contains
type(psb_ctxt_type), pointer :: ctxt type(psb_ctxt_type), pointer :: ctxt
ctxt => psb_c2f_ctxt(cctxt) ctxt => psb_c2f_ctxt(cctxt)
call psb_exit(ctxt,close=.false.) call psb_exit(ctxt,close=.false.)
deallocate(ctxt,stat=info)
return return
end subroutine psb_c_exit_ctxt end subroutine psb_c_exit_ctxt
@ -110,9 +113,12 @@ contains
type(psb_c_object_type), value :: cctxt type(psb_c_object_type), value :: cctxt
type(psb_ctxt_type), pointer :: ctxt type(psb_ctxt_type), pointer :: ctxt
integer(psb_ipk_) :: info
ctxt => psb_c2f_ctxt(cctxt) ctxt => psb_c2f_ctxt(cctxt)
call psb_exit(ctxt) call psb_exit(ctxt)
deallocate(ctxt,stat=info)
cctxt%item = c_null_ptr
return return
end subroutine psb_c_exit end subroutine psb_c_exit

@ -93,6 +93,8 @@ contains
call psb_gefree(xp,descp,info) call psb_gefree(xp,descp,info)
res = min(0,info) res = min(0,info)
deallocate(xp,stat=info)
res = min(0,info)
xh%item = c_null_ptr xh%item = c_null_ptr
return return
@ -264,6 +266,7 @@ contains
call psb_spfree(ap,descp,info) call psb_spfree(ap,descp,info)
res = min(0,info) res = min(0,info)
deallocate(ap,stat=info)
mh%item=c_null_ptr mh%item=c_null_ptr
return return
end function psb_c_dspfree end function psb_c_dspfree

@ -93,6 +93,8 @@ contains
call psb_gefree(xp,descp,info) call psb_gefree(xp,descp,info)
res = min(0,info) res = min(0,info)
deallocate(xp,stat=info)
res = min(0,info)
xh%item = c_null_ptr xh%item = c_null_ptr
return return
@ -264,6 +266,7 @@ contains
call psb_spfree(ap,descp,info) call psb_spfree(ap,descp,info)
res = min(0,info) res = min(0,info)
deallocate(ap,stat=info)
mh%item=c_null_ptr mh%item=c_null_ptr
return return
end function psb_c_sspfree end function psb_c_sspfree

@ -93,6 +93,8 @@ contains
call psb_gefree(xp,descp,info) call psb_gefree(xp,descp,info)
res = min(0,info) res = min(0,info)
deallocate(xp,stat=info)
res = min(0,info)
xh%item = c_null_ptr xh%item = c_null_ptr
return return
@ -264,6 +266,7 @@ contains
call psb_spfree(ap,descp,info) call psb_spfree(ap,descp,info)
res = min(0,info) res = min(0,info)
deallocate(ap,stat=info)
mh%item=c_null_ptr mh%item=c_null_ptr
return return
end function psb_c_zspfree end function psb_c_zspfree

@ -111,9 +111,9 @@ contains
end if end if
call psb_precfree(precp, info) call psb_precfree(precp, info)
res = min(info,0) res = min(info,0)
deallocate(precp,stat=info)
ph%item = c_null_ptr
end function psb_c_cprecfree end function psb_c_cprecfree

@ -111,9 +111,9 @@ contains
end if end if
call psb_precfree(precp, info) call psb_precfree(precp, info)
res = min(info,0) res = min(info,0)
deallocate(precp,stat=info)
ph%item = c_null_ptr
end function psb_c_dprecfree end function psb_c_dprecfree

@ -111,9 +111,9 @@ contains
end if end if
call psb_precfree(precp, info) call psb_precfree(precp, info)
res = min(info,0) res = min(info,0)
deallocate(precp,stat=info)
ph%item = c_null_ptr
end function psb_c_sprecfree end function psb_c_sprecfree

@ -111,9 +111,9 @@ contains
end if end if
call psb_precfree(precp, info) call psb_precfree(precp, info)
res = min(info,0) res = min(info,0)
deallocate(precp,stat=info)
ph%item = c_null_ptr
end function psb_c_zprecfree end function psb_c_zprecfree

@ -385,6 +385,10 @@ int main(int argc, char *argv[])
#endif #endif
/* Clean up memory */ /* 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) { if ((info=psb_c_dgefree(xh,cdh))!=0) {
fprintf(stderr,"From dgefree: %d\nBailing out\n",info); fprintf(stderr,"From dgefree: %d\nBailing out\n",info);
psb_c_abort(*cctxt); psb_c_abort(*cctxt);
@ -397,6 +401,10 @@ int main(int argc, char *argv[])
fprintf(stderr,"From dgefree: %d\nBailing out\n",info); fprintf(stderr,"From dgefree: %d\nBailing out\n",info);
psb_c_abort(*cctxt); 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) { if ((info=psb_c_cdfree(cdh))!=0) {
fprintf(stderr,"From cdfree: %d\nBailing out\n",info); fprintf(stderr,"From cdfree: %d\nBailing out\n",info);
@ -408,12 +416,15 @@ int main(int argc, char *argv[])
free(ph); free(ph);
free(xh); free(xh);
free(bh); free(bh);
free(rh);
free(ah); free(ah);
free(cdh); free(cdh);
/* further cleanup */
free(vl);
//if (iam == 0) fprintf(stderr,"program completed successfully\n"); //if (iam == 0) fprintf(stderr,"program completed successfully\n");
psb_c_barrier(*cctxt); psb_c_barrier(*cctxt);
psb_c_exit(*cctxt); psb_c_exit(*cctxt);
free(cctxt);
} }

Loading…
Cancel
Save