Use c_free for memory that has been allocated with c_malloc and c_calloc #34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was compiling the osqp_mex function against an already compiled osqp version (similar to what was described in #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.