t_result should be free'd, and not r_result - the MCMemoryAllocate is called on t_result.
 
However - I'm not quite sure about Mark's policy about the way to build string steps by steps - I think using a MCAutoNativeCharArray might a cleaner way to to do the job (no char* used then). There is a good example in MCS_loadtextfile in sysspec.cpp, but basically the idea is to instanciate a MCAutoNativeCharArray, allocate the memory using t_array.New and then passing the pointer - using t_array.Chars() - to the strcpy/strcat functions. At the end, a mere call to t_name.CreateString allows you to get the MCStringRef without having to care about releasing the memory since it is an auto pointer.