If you keep up with regular discarding and feeding, in a fresh jar each time, your lactobacillus colony will thrive. As they do, the amount of lactic acid they produce will inhibit mould growth and harmful bacteria.  A contaminated sourdough starter is pretty rare. If you do see mould growing on your starter or it develops a pink, red, or orange tinge, discard it and start again.