That's wrong. Most journalists recognise that when there's a risk of causing someone's death if they release certain details, they have to consider whether or not it's responsible to do so. So while they do exist to sell newspapers (or, more likely, get clicks for online ads) the majority of journalists and orgs aren't quite heartless enough to literally name an informant knowing it'd cause them to be exposed and killed.
In this case though, Weiner did not "literally name" the informant in The New York Times article [1]. He referred to the informant as a "retired terrorist" without giving a name.
In general, you're right about the principle of keeping sources anonymous to avoid harm. One principle in journalism ethics [2] is to "identify sources clearly" so the public can better understand a source's motives. But the other is to minimize harm ("Balance the public’s need for information against potential harm or discomfort.") to both the sources and the public, motivating anonymity in certain cases.
However, in this instance, Weiner didn't name the informant in the article.