Done correctly, freediving can be a safe activity. Done wrongly, it can be fatal. Below are the most important rules of freediving safety.
Never dive alone
The first rule of freediving safety is to dive with a buddy, aka, never dive alone. Don't practice breath-holding alone in any body of water, including pools.
Don't hyperventilate before you dive
Hyperventilation has many undesirable physiological effects for freediving and greatly increases the risk of blackout. When getting ready for a dive, just focus on relaxation, both mental and physical.
After each freedive take 3 recovery breaths
A recovery breath consists of a quick exhale, a quick inhale, and a quick hold. Repeat this 3 times. Make it a habit even on easy dives, so that you have the muscle memory for it when you need it.
Don't wear too much weight
A quick test of this is the "exhale test": if you exhale on the surface, do you sink or still float? If you sink, take off some weight. A more precise approach is to weight yourself so that you are positively buoyant at depths of 10 meters and above.
Don't exhale before you reach the surface
Sometimes in scuba diving it is appropriate to exhale while ascending. Exhaling can also very temporarily relieve the discomfort of carbon dioxide in the lungs. But your one breath contains precious oxygen, and also contributes to your buoyancy, so hold it until you return to the surface.
Take your snorkel out of your mouth before you dive
Your snorkel will prevent you from taking quick, full recovery breaths, and can also allow water into your mouth in the event of a blackout.
When line diving, wear a lanyard
Just like in rockclimbing, attaching yourself to the line with a lanyard prevents you from falling away from it if you black out.
Reading these rules is not a substitute for taking a freediving class from a certified instructor.