Nih allocation fixes v2

Hi Guys,

The original pull request got deleted when hallyn/cgmanger disappeared I think.