Actually the array is written row-major, same way as C arrays are stored. For this reason, to have it compatible with MATLAB, you need to transpose the array yourself to force col-major storage when writing to file. See e.g., https://github.com/tbeu/matio/blob/master/src/mat4.c#L195 I'd rather add new functions Mat_VarRead2and Mat_VarWrite2 to not break the API.
Just because matvar is now already nullified in Mat_VarFree. Thus second nullify...