Studies have shown that quinine can prevent cramps in your legs. One summary of the research (a systematic review) found that people who took quinine for a month had fewer leg cramps at night than those who took a dummy treatment (a placebo).  However, quinine has side effects and can be dangerous if you take too much of it.
We don't know how much quinine you should take to treat leg cramps, or how long you should take it.  Your doctor might give you 200 milligrams to 300 milligrams to take at bedtime.  You might have to take quinine for up to four weeks before you see an improvement. Also, you'll probably need to take quinine every day for it to work.
One small study (a randomised controlled trial) found that taking quinine with another drug called theophylline worked better than taking quinine on its own.  But more research needs to be done before we can say for sure whether theophylline can help treat leg cramps and is safe for this purpose.
Side effects from a normal dose of quinine aren't all that common. It might cause a ringing in your ears (known as tinnitus), headaches, stomach upsets, a temperature, blurred vision, dizziness, and itchy skin.  In studies, about 3 in 100 people taking quinine got ringing in their ears. 
A big problem with quinine is that it's poisonous if you take too much.  Too much quinine can cause a syndrome known as cinchonism.  You could feel sick, or get vomiting, headaches, tinnitus, deafness, vertigo, and disturbed vision.
You shouldn't take quinine if you're pregnant or could become pregnant.
In the US, the organisation that monitors drug safety has warned that quinine can occasionally cause severe, or even fatal, side effects.  Between 1969 and 2006, there were reports of 93 deaths in the US that were linked to quinine. US doctors are advised not to prescribe quinine for leg cramps, because the possible risk of side effects is thought to outweigh the benefits. Doctors can prescribe it if they think it will benefit a particular patient.
In the UK, doctors are advised to keep a close check on people taking quinine.  Your doctor will want to make sure you're not getting side effects.
If quinine doesn't help your leg cramps after a few weeks, you should stop taking it. Even if quinine does work, you should take a break from it every three months or so. If your cramps don't come back, there's no need to start taking it again.