Not everything needs to be sold. Sun gives out Java Standard Edition for free, but they still earn a lot from it.
IBM gives away a LOT of stuff for free, like eclipse IDE and a few other stuff. So how do they profit when they keep on giving free love? Well, the answer is, they don't profit from software alone. It is the services that made the IT industry what it is today, and many of the companies earn not from the software but from services , the value added proprietary add-ons/programs to work with these opensource projects (think eclipse and the free netbeans), and technical support for paying clients(mostly companies , not individual users). There are even some companies that are services- based alone, and these don't even provide free stuff.
Another way to earn is by letting others have the option to close the source through a special license. What do i mean? Take mysql for example. It is free, i can build a yahoo clone and earn yahoo millions based on the database. But if i change the code of the sql server, i need to give it back to the community. I dont want that, so i pay mysqlAB a licnese fee and whatever changes i created in the sql server itself will be mine, mine and mine alone! hahahaha!
These companies, they don't earn from advertisers. Advertisers earn from these guys. Heck, why build and maintain your own distribution just to earn from popups? Setting up and running a forum would be eaiser if that's what they wanted.