This line is crashing your code:
You can't re-use data pointers this way. You have essentially shared the data pointers between plhs and prhs but MATLAB doesn't know that they are sharing data pointers. So when one variable gets deleted the data pointer becomes invalid. And when the other variable (now having an invalid data pointer) tries to access the data pointer it crashes. (You also created a permanent memory leak but that is another issue).
In addition, you generally shouldn't modify the data of a prhs[ ] variable in place as that can affect other variables. So myFun( ) is non-conforming.
In general, you should use mxDuplicateArray to generate a plhs variable, and then modify the data of that variable in-place. E.g.,
array_size = mxGetNumberOfElements(prhs);
plhs = mxDuplicateArray(prhs);
a = mxGetDoubles(plhs);