Radley Balko has been all over this issue, and continues his excellent work here. This is an issue libertarians have largely ignored, but shouldn’t.
I’ve been doing some work on related issues (some of which you can read in this paper), and over time I’ve become extremely suspicious of prosecutors. Far too many of them seem to value “getting a conviction” over ensuring that the convicted person is actually guilty of the crime charged. I used to feel somewhat contemptuous of defense attorneys, wondering how anyone can defend people they know are guilty, and I still couldn’t do it myself.
But we need good criminal defense attorneys. Even with a vigorous adversarial system, prosecutors still all too frequently rely on junk science, withhold exculpatory evidence, and otherwise abuse the system. If not for lawyers willing to defend criminal defendants, guilty and innocent alike, and thus making the prosecutors develop evidence to prove their cases beyond a reasonable doubt, the situation would undoubtedly be much worse.