Add iterator test, fix invalid free of slice memory

Keys and values returned from iterators are not allocated by malloc and are
not owned by the caller, so calls to free cause problems.