config: working multivar iterator

Implement the foreach version as a wrapper around the iterator.
config: add _next() and _iterator_free()

Make it look like the refs iterator API.
config: fix leaks in the iterators