Closed traversaro closed 2 years ago
I updated the PR with a new commit ( https://github.com/traversaro/osqp-matlab/commit/09faf01f42f7a73fac0b03332e6b0f6976a943c8 ) as it turns out that there were other mismatched calls (c_malloc/mxFree), as reported in https://github.com/ami-iit/osqp-matlab-cmake-buildsystem/issues/5 . With this changes, I was able to run the complete test suite (without codegen tests).
Thanks, I don't think we had ever tried using the mex file with a version of OSQP that wasn't built for MATLAB (since we always staticly link the interface in this repo in its CMake.).
I was compiling the osqp_mex function against an already compiled osqp version (similar to what was described in https://github.com/oxfordcontrol/osqp-matlab/issues/27), and my MATLAB was crashing because quantities that were allocated with
c_malloc
andc_calloc
were then freed withmxFree
.While the direct use of
c_malloc
andc_calloc
can be converted to the correspondingmx**
allocator by definingMATLAB
for the osqp_mex compilation unit, this was not possible for the allocation done viacsc_matrix
, as fhat function is compiled as part of OSQP and whose definition can't be changed.Changing to use
c_free
for freeing all the memory that was allocated withc_malloc
andc_calloc
fixes the problem, and works as expected even ifMATLAB
is defined, as in the case of the official build procedure for the MATLAB bindings.