Fixed use of uninitialised shared_ptr illuminated by turning on libstdc++ safe iterators.