There's ```safe_(p)emalloc``` for that use case.