One of the themes of RJ, is that nothing is truely forever, even balefire. A soul is not destroyed forever by balefire, just removed from the pattern temporary to be re-threaded into the pattern by the wheel at a later date in a later age.
According to RJ (which he has stated in an interview)
1) That balefire doesn't destroy the soul forever
2) Just remove it temporary from time
3) Since it is removed temporarily from time it removes the dark one's hold on it
4) Thus the dark one can not resurrect a chosen unless the chosen is reborn and rededicates himself to the dark one, in another life, in another time, in another turning of the wheel.
5) Thus balefire frees the chosen from the dark one.
I assume that Mashadar / Shadar Logoth works the same way
1) The Mashadar eats the soul. The Dark One can no longer touch the soul for it is beyond his reach.
2) Rand destroys Shadar Logoth via the Giant Sa'angreal
3) Since Rand destroyed Shadar Logoth he destroyed Mashadar as well
4) The Dark One can not re-establish a hold to the souls for he let go and he can't reconnect unless the subject creates a bond with him
5) Eventually the soul would be reborn by the wheel