First, note that your second sentence is ungrammatical. You need to add something else to it:
The heavy use of automobiles in urban areas, which could lead to a serious air pollution problem in cities, is prohibited.
In US English, your first sentence would likely use that, not which:
I don't like stories that have unhappy endings.
Or it could dispense with both words:
I don't like stories with unhappy endings.
Only in UK English is it traditionally considered acceptable to use which with a restrictive clause if that would also work. So, in UK English, you may or may not see a comma before which. Either is acceptable, so long as the presence or lack of comma is acceptable. (I don't know enough about this UK styling to talk more about how the particular word is chosen.)
In US English, however, if either of the words sounds like it could work, then it's normally that without a comma or which with a comma.
Still, regardless of the word itself, the US and UK have the same general guideline: use a comma before a nonrestrictive clause but not before a restrictive clause.
There are situations where you would use which without a comma, even in US English:
✘ I don't know that item to choose.
→ ✔ I don't know which item to choose.
✘ That of those houses do you live in?
→ ✔ Which of those houses do you live in?