Revert "Remove spurious cast"

This reverts commit bc20427ad46f50bb127645ffc2e03059095b54d1.

The cast wasn't so spurious after all. This broke sods by counting an
offset by the size of the struct rather than using bytes.
Fix bugs reported by scan-build

Fix memory leaks and move allocation to static buffers where possible.

On Linux, the native errx() library was not used due to a typo in the
flag name.