Malloc fixes

This is following up on https://github.com/TauLabs/TauLabs/pull/498