@cazzie Typically, the buyer pays for the inspection, but the seller would likely pay to fix it if it is a problem. You are correct that once the seller knows they have a problem they would have to disclose it, and the realtor is obligated to disclose also.
Depending how the contract is written the buyer once finding out can either break the deal, the seller fixes it, or the seller might cut back money to the buyer or reduce the selling price. Again, it depends how the contract is written. Some hold together better than others.
The seller doesn’t have to ensure it’s safe exactly, he has to ensure he discloses all known hazards and things that affect the property value. The property can change hands in a hazardous state if the buyer agrees, or even if the contract is written poorly. If the contract isn’t written in a way to protect the buyer they might still be able to get out, but lose the initial deposit in escrow.
Story if your interested: I sold a very very moldy house once. I won’t tell the whole story, I didn’t know at first and when discovered on inspection the first deal fell through. A second deal when it was already disclosed the buyer chickened out and lost her deposit (eventually she got her money back from the third buyer). A third buyer knew the house was moldy (it was on my listing information) and that deal went through. The seller didn’t fix anything, the deal was always to be an As Is contract. By the time the house sold It not only had mold, it had a big bees nest visible on the outside of the house and bees also flying inside. A hurricane came through during the time of the listing and made things worse than they had been.