Ensure socket is closed on failure
Fix pointer allocation error
Add minor signed type fixes
Add additional error checking