Thanks for the patch.
Committed something similar on rB0f9b7560db36eaf1ce4d7e3e0c116f2f39e3227c.
I didn't incorporate your check for selected bones though. People should select things before running the operators, no?
You can't return in the middle of the loop. Not only this will lead to mem leakage but also other selected objects may still need to be processed.