A federal judge ordered Barry Bonds' personal trainer Greg Anderson released from prison Thursday, saying a legal "snafu" had arisen in the case.

U.S. District Judge William Alsup said Anderson must be freed because a federal appeals court hadn't affirmed his contempt order within the required 30 days.

Anderson, 40, could be returned to prison any day the appeals court affirms the Aug. 28 contempt citation for refusing to testify before a grand jury investigating whether Bonds committed perjury when he said he never knowingly used steroids.

For complete sports coverage visit FOXSports.com.

Bonds told a grand jury probing the Bay Area Laboratory Co-Operative steroid ring that Anderson gave him flaxseed oil and arthritic balm. Anderson later pleaded guilty to distributing steroids and money laundering.

Anderson, who served three months in prison and three months of home detention for his conviction, has appealed his contempt jailing on several fronts, including that his plea deal prevented him from having to cooperate with authorities.

Alsup has dismissed his claims, but the 9th U.S. Circuit Court of Appeal sent Anderson's appeal back to the judge to clarify the original contempt order, which might have averted Anderson's release.

"This snafu has arisen by an apparent failure by the court to be clear of its findings," Alsup said.

Anderson has now been imprisoned twice for refusing to testify whether Bonds used steroids. He served 15 days in July and was let out because the grand jury probing the Giants slugger had expired.

The San Francisco-based 9th U.S. Circuit Court of Appeals has never ruled on the full merits of Anderson's appeal.

The case is United States v. Anderson, 06-90292.

For complete sports coverage visit FOXSports.com.