This sort of question came up frequently in the early church. There were so many splits and heresies and troubles of all kinds. People who were baptized or received other sacraments were concerned about whether their received sacraments had been valid.
The Donatists were a group from this period who believed that we should be a church of saints, not sinners. Therefore, they held that sacraments given by a “traditori”, a church official who collaborated during the persecutions of Diocletian, were invalid. This is known as ex opere operantis, the belief that the validity of the sacraments depends on the worthiness of the minister. "They were renounced in 314D at the Council of Arles called by Constantine, but continued to exist for several hundred years.
The Catholic position given by Augustine was “ex opere operato”, the validity of the sacrament is based on the holiness of God with the minister being only his instrument. This meant that any bishop or priest, even if they were in a state of mortal sin still offered valid sacraments assuming:
- he spoke the formula for the sacrament with valid matter, correct words and signs.
- he had the intent of causing the sacrament to occur validly.
That being said, your sacrament may have been valid. The best way to know would be to speak to a Catholic priest. He should be able to tell you for sure. I would not worry too much. If you made a good confession and assumed it to be valid I don’t think it would be held against you. Whether it “counts” is another matter.