Where do the gases such as hydrogen and helium end up after leaving the earths atmosphere? I've heard that gases like hydrogen and helium leak out of the earth's gravity a little by little. 
but where are they going? where do they end up after leaving earth's pull?
would the sun pull them towards itself? or they just wander in space until they find another space object with some mass?
 A: It takes a long time for hydrogen and helium to work their way to the outer reaches of Earth's atmosphere, millions of years. The outer layers of the atmosphere are the thermosphere and the exosphere. These layers are very tenuous, but the gas in them is still considered to be gravitationally bound to the Earth. The thermosphere begins about 80 km above sea level, the base of the exosphere ranges from about 500 to 1,000 km above sea level depending on solar activity. (The altitude of the ISS is 408 km).
When gases leave the exosphere they get swept up by the solar wind, a stream of charged particles released from the upper atmosphere of the Sun which blows through the solar system. This wind is very thin - in Earth terms it's a hard vacuum, but it is moving quickly. 
The solar wind is observed to exist in two fundamental states, termed the slow solar wind and the fast solar wind. Near Earth, the slow solar wind has a speed of 300 - 500 km/s, and a temperature around 100,000 K, the fast solar wind has a typical speed of 750 km/s and a temperature around 800,000 K.
So our lost hydrogen and helium (and other gases) eventually get blown by the solar wind to the outer limits of the solar system, unless they happen to bump into a planet, moon, or asteroid in the mean time.
For more details on the exact mechanisms by which various gases escape Earth's atmosphere, please see Wikipedia's article on atmospheric escape.
