A belated further thought: you could typedef the return type (char*) to a new type-name, then have a typemap entry that handles the OUTPUT of that with that code-snippet: https://perldoc.perl.org/perlxstypemap.
Comment on Re^2: Perl, C and deallocation responsibility
Thanks for those suggestions. I'll see if I can get time to play with them today.
Given time constraints I came up with a much hackier solution (static pointer to a string which is used every call. Not thread safe, but in this case, not an issue), but I want to do it cleanly!