I think that this malloc should happen first. In theory the malloc can fail which would leak the socket. Failing in malloc is currently an abort, but we don't want it to be like that forever.