Not quite. The railroads were given the land at a price - they had to carry mail for the government at less-than-market rates. That continued until World War II. If you consider that many of the land grants were around 1870, that was 70 to 75 years of carrying the mail at less than cost. Then, during WWII, the federal government was desperate for revenue, and they let the railroads buy their way out of the existing deal.
The land wasn't just "granted free" to the railroads.