What would happen if software companies like Microsoft or Apple released their code bases?If Microsoft released its codebase, its profits would fall almost overnight. Almost all of its profitability comes from Office + business software, Windows and server software (Where Microsoft's Profits Come From), with its hardware and entertainment divisions actually losing money. It's unlikely that most organizations would buy official support for Microsoft products, and without any remaining reason to pay those licenses, the corporation would shrivel up and die.
Apple is another matter. Its revenues largely come from iPhone, iPad and Mac laptops. Furthermore, its operating systems are, in part, based on the open source Darwin; see Apple's Open Source Release page for a list of tools they already release. Apple also leads The WebKit Open Source Project, which is the open source browser engine behind Safari, Chrome, Opera and others.
Generally, if it's supported by the business model and the project is run in an efficient but opinionated way, open sourcing an application will improve its quality and security over time. It can also lower development and testing costs in some cases.
Competitors and patent trolls will inspect all the code, hunt down violations, and attack.