Block trust region MEX: fix memory leak in MATLAB function closure

time-shift
Sébastien Villemot 2020-09-07 16:13:59 +02:00
parent 0b41d17374
commit 35a162c6a6
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 6 additions and 1 deletions

View File

@ -11,7 +11,7 @@
! be set in order to give the input values for the indices that are not passed
! to matlab_fcn.
! Copyright © 2019 Dynare Team
! Copyright © 2019-2020 Dynare Team
!
! This file is part of Dynare.
!
@ -80,12 +80,16 @@ contains
if (mexCallMATLAB(nlhs, call_lhs, int(size(call_rhs), c_int), call_rhs, "feval") /= 0) &
call mexErrMsgTxt("Error calling function to be solved")
call mxDestroyArray(call_rhs(2))
fvec_all => mxGetPr(call_lhs(1))
if (associated(f_indices)) then
fvec = fvec_all(f_indices)
else
fvec = fvec_all
end if
call mxDestroyArray(call_lhs(1))
if (present(fjac)) then
fjac_all(1:n_all,1:n_all) => mxGetPr(call_lhs(2))
if (associated(x_indices) .and. associated(f_indices)) then
@ -93,6 +97,7 @@ contains
else
fjac = fjac_all
end if
call mxDestroyArray(call_lhs(2))
end if
end subroutine matlab_fcn
end module matlab_fcn_closure