I think most people have experienced this. I call it "triangulation"... because rather than speak to you directly about their issue with you, they talk to someone else about it (creating a triangle), and not in a "can you give me advice to improve the relationship?" kind of way, but just complaint or sometimes even slander.
I agree it isn't very mature, but i've seen people of all ages do it. I try to remember too if i'm the one being "confided in" to ask the person if they've talked to so-and-so yet and tell them bluntly they've got to do that, and to try to say things that diffuses the negativity, rather than join in with any fault finding.
When i've been caught on the receiving end i sometimes try to talk to the person about their complaints. It's tricky... if i'm feeling defensive, it won't work. I have to be caring and genuinely interested in listening for it to have any chance of working. And then again... sometimes they're just not worth it and you can find better friends.