MATLAB: Seg fault associated with MEX file

crashmex fileseg fault

I'm getting a seg fault show up while running a matlab script that includes a call to a MEX file. The MEX file is called exactly once, and I've checked that the crash does not actually happen during the invocation of the MEX file by displaying text just before and after the MEX call. I'm working on trying to narrow down the location of the seg fault, but the script is long and only crashes after a couple of hours so this is tricky. Any other ideas? Here is the crash dump:
Abnormal termination: Segmentation violation
Register State (from fault): EAX = 00ba840f EBX = 01208728 ECX = a3a60fb0 EDX = 1342d000 ESP = 048d8e2c EBP = 048d8e68 ESI = 00bc426b EDI = 00000000
EIP = 00000000 EFL = 00010246
CS = 00000073 DS = 0000007b SS = 0000007b
ES = 0000007b FS = 00000000 GS = 00000033
Stack Trace (from fault): [ 0] 0x00941099 /usr/local/MATLAB/R2011a_Student/bin/glnx86/../../bin/glnx86/libmwfl.so+00450713 fl::sysdep::linux::unwind_stack(void const**, unsigned int, unsigned int, fl::diag::thread_context const&)+000036 [ 1] 0x008f224a /usr/local/MATLAB/R2011a_Student/bin/glnx86/../../bin/glnx86/libmwfl.so+00127562 fl::diag::stacktrace_base::capture(fl::diag::thread_context const&, unsigned int)+000180 [ 2] 0x008fc473 /usr/local/MATLAB/R2011a_Student/bin/glnx86/../../bin/glnx86/libmwfl.so+00169075 [ 3] 0x008fc845 /usr/local/MATLAB/R2011a_Student/bin/glnx86/../../bin/glnx86/libmwfl.so+00170053 fl::diag::terminate_log(char const*, fl::diag::thread_context const&, bool)+000115 [ 4] 0x002c0a0f /usr/local/MATLAB/R2011a_Student/bin/glnx86/../../bin/glnx86/libmwmcr.so+00375311 fl::diag::terminate_log(char const*, ucontext const*, bool)+000096 [ 5] 0x002bd8a6 /usr/local/MATLAB/R2011a_Student/bin/glnx86/../../bin/glnx86/libmwmcr.so+00362662 [ 6] 0x002bf56e /usr/local/MATLAB/R2011a_Student/bin/glnx86/../../bin/glnx86/libmwmcr.so+00370030 [ 7] 0x002c0154 /usr/local/MATLAB/R2011a_Student/bin/glnx86/../../bin/glnx86/libmwmcr.so+00373076 [ 8] 0x004c3410 __kernel_rt_sigreturn+000000

Best Answer

In such cases, your mex file has probably overwritten a pointer, or overwritten a data area that does not belong to it but which other code is depending upon to be correct. Or your mex file might be free()'ing something that it should not be.
Related Question