A Los Angeles judge overturned a ruling on Friday to deny Lohan bail and send her into custody at a Lynwood, California, jail.

'An order has been signed by Judge Patricia Schnegg granting writ of habeas corpus,' court spokesman Allan Parachini said on Friday night.'Bail has been set at $300,000.'

Within hours the bail had been posted and Lohan walked free.

Judge Schnegg ruled, however, that Lohan must be fitted with a SCRAM alcohol-monitoring device.

She has also been ordered to keep away from shops that primarily sell alcohol, until her next appearance in court on 22 October.

The judge will then decide whether she formally violated her probation by failing the drugs test.

Fall: Lindsay Lohan in her latest mugshot, taken earlier this week, left. Right, Lohan in 2007, in the year in which the images are said to have been taken

Lohan was ordered to jail until an Oct. 22 hearing after she admitted failing at least one court-ordered drug test in her three-year DUI case and was handcuffed and taken away.

Lindsay's reaction was apparently that of shock when she was remanded in custody.

She is said to have looked at her lawyer before being taken out of the courtroom.Judge Fox scheduled a formal probation hearing for 30 days from now when Lindsay will have to answer to her failed drug tests.

He had previously warned Lohan he would put her back behind bars if she tested positive or skipped one of her twice-weekly tests.

The Probation Department will apparently not recommend jail time for the second failed drug test because of an ambiguity in the paperwork.

Welcome to the circus: Media gather at Lynwood Jail to wait for news of Lohan

More controversy: The 24-year-old has been caught on camera apparently injecting heroin

It has also been claimed Lohan is planning to voluntarily check back into rehab, despite relapsing just weeks after being released from her court-ordered stay in Ronald Reagan UCLA Medical Centre.

A source told People.com: 'She will step up her treatment and do more than what she was previously ordered to do.'

If she does check back into a centre, it will be Lohan's fifth stay in rehab.The actress previously spoke about her time in rehab, describing it as a 'vacation'.In an interview earlier this year with America's OK! magazine, Lohan explained: 'Well, the second two times I went into rehab, to be honest with you, I had to go because it was a court thing.

'It was an obligation. I had to do it to stay out of getting any jail time. And I took responsibility for that. And it was like a vacation.

'But it was a positive experience. When I was there it was like, there’s a lot of people that I know who should really be here now, not for drugs or alcohol abuse - just to learn about life. The world is nuts.'