[RDY] Refactor alloc() calls.

Converting calls to `alloc` to `xmalloc` or `xmallocz`. I will leave any `alloc` call that has non-trivial error handling. Those will have to refactored in a separate PR.

Other refactorings:
* don't cast the return value of xmalloc
* let the compiler implicitly cast the arguments to xmalloc
* replace `sizeof(actual_type)` with `sizeof(*lhs)`