i'm not completely familiar with the code, but afaict you are not allowed to call malloc in this method, because it can be called from the real-time thread.