[fix] free the layer's datastructure and close the socket that may have been opened