Charles Leclerc almost hit the barriers after losing control of his Ferrari in the opening practice session in Baku.