After a quick google search, I found some information on the FINRA website (Financial Industry Regulatory Authority).
Short answer - there are measures in place to handle if a brokerage goes under. Usually the accounts are transferred to another firm, and you will have access to your money within 1-3 months.
Long answer - Here are some things to keep in mind:
- You probably won't have access to your funds for a while during the change process.
- But, you probably won't lose your money either. The firms are required to keep their own and their client's money separate, and keep some amount of capital on hand.
- In addition to that, firms are usually members with the SIPC which "covers missing stocks and other securities up to $500,000" - similar to the FDIC and bank accounts.
- If a firm that you have accounts with does go under, make sure that you keep all paperwork and records that you have. And be ready to fill out some forms.
The webpage has more information and includes additional resources at the bottom of the page.
NOTE: This is USA specific, and is probably different for other countries.