Unwrap and fixup memory leaks
The fix in !98 (merged) flagged:
- new extra memory leak
- the existing style/calling convention is fragile
Rework the latter and address the former.
The fix in !98 (merged) flagged:
Rework the latter and address the former.