I bought a Kahr P-45 cheap, because it was filthy and jammed every third or fourth round. The gun shop/shooting range actually let me fire it first, because I was a regular customer. It had two failures to feed in the one magazine I fired, and they knocked off $50 on the spot.
I took it home and cleaned it, shined the feed ramp up a little and returned to the range with four different types of .45 ammo. It loved Sellier & Belliot FMJ's, never jamming once. I fired 50 rounds of it, and then tried the other brands, and they all worked, too, including the Speer Gold Dots that I wanted to carry for an SD round.
My conclusion was that somebody bought it new, fired a box or two of really dirty ammo through it, experienced many failures, couldn't hit anything with it, and found the recoil to be too heavy. When I finished cleaning it, it looked brand new, and was eventually reliable enough that I carried it a lot.
So, I don't worry too much about buying a dirty gun, as long as it shows no signs of abuse. It is my belief that the overwhelming majority of handgun owners never learn to shoot them very well, and soon stop trying. The result is that there are a great number of used guns out there that look like hell, but actually are not even broken in, yet.