Cody Gregg, 29, was arrested on August 12, 2019, and, according to a probable cause affidavit seen by The Oklahoman, when Gregg's backpack was searched, an officer found a baggie that contained "a large amount of white powder substance that I believed to be cocaine."

The affidavit said the powder "later tested positive for cocaine and was a total package weight of 45.91 grams of cocaine."

Oklahoma Police charged Gregg with trafficking illegal drugs and he was jailed on a $50,000 bond. He initially pleaded not guilty, but in October he changed his plea.

Days later Gregg withdrew his guilty plea after lab tests showed the powder was actually powdered milk. He told the judge that he got the powdered milk from a food pantry.

Gregg told a judge that he had pleaded guilty because he wanted to get away from poor conditions in the Oklahoma County Jail, according to the Washington Post.

Visit Insider's homepage for more stories.

A homeless man in Oklahoma was sentenced to 15 years in prison after pleading guilty to trafficking cocaine, but his case was dismissed after the substance turned out to be powdered milk.

Cody Gregg, 29, had his case in Oklahoma City dismissed on Friday, days after pleading guilty to possession of cocaine with intent to distribute, The Oklahoman reported.

Gregg told a judge that he initially pleaded guilty because he wanted to get away from poor conditions in the Oklahoma County Jail, which is plagued with overcrowding, chronic mold, and a high suicide rate, according to the Washington Post.

Thirty-five inmates have died while in custody at the jail since 2016, according to The Enid. The design of the building, say experts, has contributed to a culture of violence. Guards have poor visibility into holding areas, and inmates have been able to rip up pieces of the drop ceiling to create weapons.

Gregg was arrested on August 12, 2019, and, according to a probable cause affidavit seen by The Oklahoman, when Gregg's backpack was searched, an officer found a baggie that contained "a large amount of white powder substance that I believed to be cocaine based on my training and experience."

Read more: A 14-year-old boy shot his way in to a school before turning the gun on himself. Now his mother is facing 6 felony charges.

At the time of his arrest, Gregg was on probation and had been arrested three times on drug-related charges since 2014, The Washington Post reported.

The affidavit said the powder "later tested positive for cocaine and was a total package weight of 45.91 grams of cocaine."

According to a ProPublica investigation from 2016, thousands of people are jailed every year because roadside drug tests produce false positives. In Gregg's case, the powder later was proved to be powdered milk.

But still, police charged Gregg with trafficking illegal drugs and he was jailed on a $50,000 bond.

He initially pleaded not guilty, but in October he pleaded guilty to possession of a controlled dangerous substance with intent to distribute in an attempt to be moved out of the jail. Days later, his plea was reversed after his public defender pointed out the new evidence showing the powder tested negative for cocaine. He was freed on Friday.

Insider has contacted the Oklahoma City Police Department for comment.