Fix potential socket leak in opennet()