Clean up memory allocation checks and mem leak in main().

Granted, if we fail to allocate the sizes needed to decode and encode
the world is in a lot of hurt...