Yeah, that's going to crash for sure. A couple of things:
1) prhs is a read-only input. You should not be trying to free anything associated with prhs.
2) mxGetPr returns a pointer to memory that was allocated with the MATLAB memory manager. You should never try to free up this memory with any native C/C++ method such as free or delete. You can only use mxFree for this (or mxDestroyArray for mxArray variables), and then only if the memory in question is temporary memory that was allocated by you inside the mex routine itself.
3) Even putting 1 and 2 aside, and even if the delete was used properly, rawdata is passed in by value to main ... setting it to 0x0 inside main does nothing to the original variable that was passed in. I.e., this won't change rawdata to 0x0 inside mexFunction. This is a basic C/C++ programming mistake.
Regarding your apparent memory leak, we don't have enough to go on. You will have to show more code.