Fix compilation for removed modules
Replace safemalloc with x* requivalents

It's insane to have casts to malloc and other functions, so remove those.
Whilst there, standardise the wrappers we use.