There is a term in sacramental theology known as the Seal of Confession. The priest is bound by virtue of his ordination to absolute privacy of the penitent. This closure assures that the sacramental seal shall not be violated. Because of this, when people go to the sacrament of Penance, they know that their most private of actions will be kept just private. Only God, the priest, and the penitent will ever know.
If a priest violates the seal, he is automatically excommunicated and defrocked. Only the pope himself can rescind this ultimate penalty. If the penitent wants to discuss any sin confessed in the confessional with the priest outside the confessional, the priest must demand that he start from the beginning; the priest cannot bring any knowledge from inside the confessional outside and vice versa.
When a priest needs to seek advice or counsel about a sin (maybe there is a need to remove a censure that is reserved to the bishop of the diocese, for example) he has to ask the penitent for permission. Once permission is granted from the penitent, he is never referred to by name so that no one could ever figure out who confessed the sin.
Information that is gathered inside the confessional can never be used outside the confessional. To do so would violate the seal of confession. For example, if a person confesses to murdering someone, the priest who heard the confession cannot go to the authorities and turn in the penitent. The priest can advise the penitent that going to the police and confessing is a moral duty, but can never demand it or report the penitent.
There was a famous case in the Baltimore Archdiocese about forty years ago in which a known murderer went to Confession. The priest was summoned to trial and put on the stand. In no way could he violate the sacred seal. Ultimately, he was put into prison for not telling the information he received in the sacraments. Finally he was released, and the laws were changed to protect confessors and the rights of penitents to seek confession without a word being released.
A person who sins and goes to Confession should never fear disclosure. Not only is there a severe penalty on the violation, but the Holy Spirit gives a special gift to the priest, in which he forgets what he hears in confession.