1df42798d4
I suspect code here can be cleaned up but for now try this. Alternatively we can check for errors around buffer allocation but this needs bigger changes.