I occasionally worry about things like that, but mainly because I sometimes write about ideas that I think some people would find very upsetting rather than because of possible legal issues as you mentioned in some other comments below. But in either case, one possible solution is to write about things metaphorically, such that you know what you're writing about, but anyone else would require some additional information to know what you actually mean.