Okay so here AEGetParamPtr is expecting a buffer it can write chars to in the 5th parameter. At the moment you are passing the c-string buffer owned by the AEanswerErr stringref to it, which you can't do. This part should be this:
```
char *t_buffer;
t_buffer = new char[rSize + 1];
AEGetParamPtr(ae, keyErrorString, typeChar, &rType, t_buffer, rSize, &rSize);
/* UNCHECKED */ MCStringCreateWithNativeCharsAndRelease((char_t *)t_buffer, rSize, AEanswerErr);
```