Why I have memory leak in C/MEX? -


i'm totally beginner in c/mex. simple code call "magic" function matlab. have no idea why "out of memory" message.

#include <mex.h> void mexfunction(int nlhs, mxarray *plhs[], int nrhs, const mxarray *prhs[]) {     #define a_in prhs[0]     #define a_out plhs[0]     mxarray *r;     r=mxcreatedoublematrix(a_in,a_in,mxreal);     mexcallmatlab(1, r, 1, &a_in, "magic");     a_out = mxduplicatearray(r);     mxdestroyarray(r);     return; } 

a_out seems duplicate of r. basically, according doc (that should read before asking question, sayin' :) ), creating new array. calling function allocate more memory store copy.

so leak a_out. can use valgrind tool finding those, options --leak-check=full. of course, compile debug flags of compiler (-g3 gcc), give of informations need fix leaks.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -