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 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 tolf 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 it is permitted to kill oneself to atone for a sin. Assuming that to be right, would it follow on that it is permitted to kill oneself prior to sinning in order not to sin if that is the only way?