Natural Gas and Propane fueled appliances are equipped with a device called a thermocouple.
The job of the thermocouple is to sense heat from the pilot light and when the pilot light goes out and the thermocouple no longer senses any heat then the thermocouple sends an electrical signal to the gas solenoid valve which shuts the gas off so no gas will leak inside your house.
If it weren't for that little thermocouple then gas could leak inside your house and then when you went to light the pilot again an explosion could happen.
So as long as you have a thermocouple on your gas appliance and it's working properly then no gas should ever leak if the pilot light goes out.