How to prevent a coauthor from stealing the article?
In this age, it seems highly unlikely that there is absolutely no permanent record of their communication and collaboration: how did they collaborate in writing the paper? Did they exchange drafts via e-mail, for instance?

So, if this happens, you simply show the evidence to the editors and to the direct superiors of prof. B. End of story.