Make sure that the pickle has enough vinegar and oil. Both the oil and vinegar prevent fungal and bacterial growth. Additionally adding enough salt also helps in prevention of bacteria. This article explains the topic in depth if it interests you.