The Gemoro in Kiddushin 81b brings down the following (shortened version of the) story:
Rabbi Chiya Bar Ashi used to say 'May God save me from the Yetzer Hora'! When his wife overheard him she said he is anyway old already, why does he need to pray such? She dressed herself up as a prostitute and paraded in front of him. She told him she was a famous protistute who had just returned from overseas. He requested relations with her and she said 'first fetch me that pomegranate'. Meanwhile she dissappeard. When he came home he went and sat in the oven. When his wife asked him what he was doing he told her the story. She then told him not to worry because it was herself anyway, and he only believed her after she proved it with Simonim. However he fasted the rest of his life to repent on trying to do an aveirah.
Rashi says why did he sit himself in the oven? 'To kill himself'!
Can we deduce from here that Rabbi Chiya Bar Ashi held it is permitted to kill oneself to atone for a sin? If so, would it follow that he would hold it is permitted to kill oneself prior to sinning in order to avoid a sin if that is the only way?
Please note that all Halachic decisors from later generations to today agree that the Halacha is that it is forbidden to kill oneself, and no one should assume the law is otherwise based on this story. This question is to understand the implication of R' Chiya Bar Ashi's actions only!