Freeing socket in the wrong position