Make all alloc calls cleanly cleanup and close the connection on errors.

It's not clear that this is worth it, and using a publib xmalloc() to
just die might be better, particularly given libev doesn't guarantee
any behaviour when mallocs start failing.

Remove a reduntant NULL check before free(), which is documented
to do nothing on NULLS.