Indeed, there were a few possible leaks here. Fixed in new PR, using static buffers where possible, and only one allocation for the other cases.