I am writing an image registration program and I find that a strange error when using mkl_free(). I wrote an implementation of the matrix exponential function - expm() - from MATLAB using MKL functions. I have tested it individually by itself and it works without running into any errors.
The code can be found here: https://github.com/poliu2s/MKL/blob/master/matrix_exponential.cpp
The problem occurs when I call it from other functions who need it for calculation. My program currently crashes right before I call the first mkl_free() so I suspect it is some form of memory leak. But shouldn't matrices used within the function be self contained? I do not see how freeing them would cause my entire program to crash.
Calls to mkl_free_buffers(); and mkl_thread_free_buffers(); produce no effect that I can observe. I have tried turning off the Intel Memory Manager with mkl_disable_fast_mm() at the cost of speed at the beginning of the program's execution but also to no avail.
I have checked the inputs going into the function itself and the matrix is perfectly valid - just like the ones I used during testing.
Does anyone have any suggestions as to why my program crashes when I call mkl_free(array)?