Sefer Chofetz Chaim Chapter 6 halacha 3,4

Halacha 3: Don’t think that because there is a Torah level prohibition to just listen to lashon hara then you are stuck and can’t keep your ears open to avoid problems that might come your way. Rather you are allowed to listen to lashon hara if it could be used constructively for yourself in the future or if you can fix a matter for someone else or change the person being talked about and the like. What one should do is if you see someone coming over to you tell you something you must ask him, “is it constructive for me or can I help to resolve an issue?” If he replies yes then fine you can listen but don’t accept what he says as truth until you look into the matter yourself but if he sounds like he’s speaking out of hatred and is about to just go all out degrading someone then you should tell him you don’t want to listen or at least give him a disparaging look. This is essential in order so that he won’t come over to you again with more lashon hara and he might even stop speaking altogether because of the shame you caused him.

Halacha 4: There are times when it’s a mitzvah to listen to lashon hara which is when you figure out yourself that you think by listening fully to what he says you can convince him and others listening that he is wrong and defend the person being spoken about by judging the person being talked about favorably. If you feel the speaker will just twist whatever positive words you have and make things worse then you should stay quiet until he walks away and then defend the one being talked about in front of the listeners. Even if you started to listen unlawfully there is a way to fix your sin of “lo sisa shema shav” and retroactively it’s as if you never sinned by judging him favorably and defending him so that people will believe you and not the one who spoke the lashon hara. And if you can convince the one speaking that he is wrong you Also fixed your sin of placing a stumbling block in front of the blind. If you can break up a fight it’s a mitzvah to listen to lashon hara just as the Gemara in Avoda Zara 18b says it’s forbidden to go into non-Jewish entertainment centers like movie theaters but if you can save a wayward Jews from these places then you are permitted to go in there and get him out, for example there are many stories of rabbis going into movie theaters or bars to save teenagers from these immoral places and the like. Also, if a person feels he has to vent to someone after someone did something nasty to him, or the like, then a person should listen to the venting if he will be sure not to believe what is being said and it will calm down the person who got riled up so hope no argument will ensue. It is a mitzva to listen so that hopefully he won’t speak to anyone else who might accept what he says and you creating peace amongst the Jews and the world. For this reason, you can even ask the guy venting why he dislikes his friend so that maybe you can fix the matter.