memory leak in C Mex file
Show older comments
Hello,
I wrote a C mex script, and it runs, however, after running it several times, it crashes Matlab, meaning that there is a memory leak somewhere.
This is the first time I tried to pass into the MEX routine a 2D matrix, so it's probably what's causing the problem.
The 2D matlab matrix is called "connectivity"
Within mexFunction I define the following:
connectivity_pointer = (double *) mxGetPr(prhs[9]);
/*create 2D array for connectivity */
connectivity_M = mxGetM(prhs[9]);
connectivity_N = mxGetN(prhs[9]);
connectivity = mxCalloc(connectivity_N,sizeof(double*));
for (j=0;j<connectivity_N;j++){
connectivity[j]=connectivity_pointer+connectivity_M*j;
}
/*do stuff*/
mxFree(connectivity);
return;
Is this correct?
I have no idea what it could otherwise be.. On a side note, I have the new Yosemite, Matlab 2014b, and XCode 5.0, and every time I try to create a MEX debugging session with XCode it crashes (even before attaching processes)! Anyone experienced that?
Francesco
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!